7#include "min-cpp-version/cpp17.h"
10#include <magic_enum/magic_enum.hpp>
11#include <magic_enum/magic_enum_utility.hpp>
18 using namespace magic_enum;
22 template <
typename ENUM_TYPE>
26 using enum_type = ENUM_TYPE;
27 using underlying_type = std::underlying_type_t<enum_type>;
31 circular_enum& operator++()
noexcept {
32 value = magic_enum::enum_next_value_circular(value);
35 operator enum_type()
const noexcept {
return value; }
38 template <
typename ENUM_TYPE>
40 constexpr auto IncWrap(ENUM_TYPE& val)
noexcept
42 val = magic_enum::enum_next_value_circular(val);
46 template <
typename ENUM_TYPE>
48 constexpr auto DecWrap(ENUM_TYPE& val)
noexcept
50 val = magic_enum::enum_prev_value_circular(val);
57 template <
typename VALUE_TYPE,
typename ENUM_TYPE>
59 struct enum_array :
public std::array<VALUE_TYPE, magic_enum::enum_count<ENUM_TYPE>()>
61 using array_type = std::array<VALUE_TYPE, magic_enum::enum_count<ENUM_TYPE>()>;
63 using value_type = VALUE_TYPE;
64 using size_type =
typename array_type::size_type;
65 using difference_type =
typename array_type::difference_type;
66 using pointer =
typename array_type::pointer;
67 using const_pointer =
typename array_type::const_pointer;
68 using reference =
typename array_type::reference;
69 using const_reference =
typename array_type::const_reference;
70 using iterator =
typename array_type::iterator;
71 using const_iterator =
typename array_type::const_iterator;
72 using reverse_iterator =
typename array_type::reverse_iterator;
73 using const_reverse_iterator =
typename array_type::const_reverse_iterator;
77 using enum_type = ENUM_TYPE;
81 [[nodiscard]]
constexpr reference
at(ENUM_TYPE pos) {
82 return this->array_type::at(magic_enum::enum_index(pos).value());
85 [[nodiscard]]
constexpr const_reference
at(ENUM_TYPE pos)
const {
86 return this->array_type::at(magic_enum::enum_index(pos).value());
89 using array_type::operator[];
91 [[nodiscard]]
constexpr reference operator[](ENUM_TYPE pos)
noexcept {
92 return this->array_type::operator[](magic_enum::enum_index(pos).value());
95 [[nodiscard]]
constexpr const_reference operator[](ENUM_TYPE pos)
const noexcept {
96 return this->array_type::operator[](magic_enum::enum_index(pos).value());
auto iterator(T &cont, RANDOM &rng=::ghassanpl::random::default_random_engine)
Returns an iterator to a random element in cont.
constexpr decltype(auto) at(random_access_range auto &range, std::integral auto index)
Returns a reference to the value at index of range.
Primary namespace for everything in this library.
GHPL_REQUIRES(std::is_enum_v< ENUM_TYPE >) struct circular_enum
TODO: Finish this.