20 #include <string_view>
31 template<
typename Definition>
38 static_assert(std::is_enum_v<enum_type> && !std::is_convertible_v<enum_type, int>,
"Enum is not a scoped enum");
48 return std::string{Definition::values[
static_cast<int>(key)]};
57 static constexpr utils::optional<enum_type>
get_enum(
const std::string_view value)
59 for(
unsigned int i = 0;
i <
size();
i++) {
60 if(value == Definition::values[
i]) {
64 return utils::nullopt;
73 static constexpr utils::optional<enum_type>
get_enum(
unsigned long value)
78 return utils::nullopt;
85 static constexpr std::size_t
size()
87 return Definition::values.size();
96 #define ENUM_AND_ARRAY(...) \
97 enum class type { __VA_ARGS__ }; \
98 static constexpr std::array values{__VA_ARGS__};
100 #define ENUM_AND_ARRAY(...) \
101 enum class type { __VA_ARGS__ }; \
102 static constexpr std::array<std::string_view, std::tuple_size_v<decltype(std::make_tuple(__VA_ARGS__))>> \
The base template for associating string values with enum values.
static constexpr std::size_t size()
static std::string get_string(enum_type key)
Converts a enum to its string equivalent.
static constexpr utils::optional< enum_type > get_enum(const std::string_view value)
Converts a string into its enum equivalent.
static constexpr utils::optional< enum_type > get_enum(unsigned long value)
Converts an int into its enum equivalent.
typename Definition::type enum_type
std::array< T, size()> sized_array
Provide a alias template for an array of matching size.