header_utils
Loading...
Searching...
No Matches
enums.h
1
4
5#pragma once
6
7#include <magic_enum.hpp>
8#include <concepts>
9#include <array>
10
11namespace ghassanpl
12{
13 namespace enums
14 {
15 using namespace magic_enum;
16 }
17
20 template <typename VALUE_TYPE, typename ENUM_TYPE>
21 requires std::is_enum_v<ENUM_TYPE>
22 struct enum_array : public std::array<VALUE_TYPE, magic_enum::enum_count<ENUM_TYPE>()>
23 {
24 using array_type = std::array<VALUE_TYPE, magic_enum::enum_count<ENUM_TYPE>()>;
25
26 using value_type = array_type::value_type;
27 using size_type = array_type::size_type;
28 using difference_type = array_type::difference_type;
29 using pointer = array_type::pointer;
30 using const_pointer = array_type::const_pointer;
31 using reference = array_type::reference;
32 using const_reference = array_type::const_reference;
33 using iterator = array_type::iterator;
34 using const_iterator = array_type::const_iterator;
35 using reverse_iterator = array_type::reverse_iterator;
36 using const_reverse_iterator = array_type::const_reverse_iterator;
37
38 using enum_type = ENUM_TYPE;
39
40 [[nodiscard]] constexpr reference at(ENUM_TYPE pos) {
41 return this->array_type::at(static_cast<size_type>(pos));
42 }
43
44 [[nodiscard]] constexpr const_reference at(ENUM_TYPE pos) const {
45 return this->array_type::at(static_cast<size_type>(pos));
46 }
47
48 [[nodiscard]] constexpr reference operator[](ENUM_TYPE pos) noexcept {
49 return this->array_type::operator[](static_cast<size_type>(pos));
50 }
51
52 [[nodiscard]] constexpr const_reference operator[](ENUM_TYPE pos) const noexcept {
53 return this->array_type::operator[](static_cast<size_type>(pos));
54 }
55 };
56}
constexpr auto bit_count
Equal to the number of bits in the type.
Definition bits.h:33
Primary namespace for everything in this library.
Definition align+rec2.h:10
Same as std::array except it takes an enum type instead of the size, and uses magic_enum to determine...
Definition enums.h:23