21 static constexpr
char chars[
sizeof...(C) + 1] = {C...,
'\0'};
35 typedef typename apply_range<count - 1, meta_functor, count - 1,
40 template <
template <
std::size_t...>
class meta_functor,
48 static constexpr
const char *
chars[
sizeof...(S) + 1] = {S::chars...,
53 template <
class... Strings,
char... C>
60 template <
class... Strings,
char... Cp,
char C0,
char... C>
63 if constexpr (C0 ==
' ' || C0 ==
'\t')
66 else if constexpr (C0 ==
',')
90 #define REACTIONS_POW_ENUM(enum_name, ...) \ 91 enum enum_name : int { __VA_ARGS__ }; \ 93 struct enum_name##_properties { \ 95 static constexpr std::size_t size = \ 96 std::initializer_list{__VA_ARGS__}.size(); \ 98 static constexpr enum_name list[size] = {__VA_ARGS__}; \ 100 template <enum_name E, std::size_t I = 0> \ 101 static constexpr auto index_impl() { \ 102 static_assert(I < size); \ 103 if constexpr (list[I] == E) \ 106 return index_impl<E, I + 1>(); \ 109 template <enum_name E> static constexpr auto index() { \ 110 return index_impl<E>(); \ 125 #define REACTIONS_POW_ENUM_WITH_UNKNOWN(enum_name, ...) \ 126 enum enum_name : int { unknown_##enum_name = 0, __VA_ARGS__ }; \ 128 struct enum_name##_properties { \ 130 static constexpr std::size_t size = \ 131 std::initializer_list{__VA_ARGS__}.size(); \ 133 static constexpr enum_name list[size] = {__VA_ARGS__}; \ 135 template <enum_name E, std::size_t I = 0> \ 136 static constexpr auto index_impl() { \ 137 static_assert(I < size); \ 138 if constexpr (list[I] == E) \ 141 return index_impl<E, I + 1>(); \ 144 template <enum_name E> static constexpr auto index() { \ 145 return index_impl<E>(); \ 148 static enum_name from_string(const char *s) { \ 150 for (; i < size; ++i) \ 153 struct constexpr_string_type { \ 154 const char *chars = #__VA_ARGS__; \ 156 return reactions::pow_enum::parse_string( \ 157 reactions::pow_enum::apply_range< \ 158 sizeof(#__VA_ARGS__) - 1, \ 159 reactions::pow_enum::string_builder< \ 160 constexpr_string_type>::produce>::result{}); \ 165 return unknown_##enum_name; \ 168 static enum_name from_string(std::string const &s) { \ 169 return from_string(s.c_str()); \ 172 static const char *to_c_string(enum_name e) { \ 174 for (; i < size; ++i) \ 178 struct constexpr_string_type { \ 179 const char *chars = #__VA_ARGS__; \ 181 return reactions::pow_enum::parse_string( \ 182 reactions::pow_enum::apply_range< \ 183 sizeof(#__VA_ARGS__) - 1, \ 184 reactions::pow_enum::string_builder< \ 185 constexpr_string_type>::produce>::result{}); \ 189 static std::string to_string(enum_name e) { return to_c_string(e); } \
Group of string templates.
Definition: pow_enum.hpp:47
constexpr auto parse_string_impl(string_group< Strings... >, string_tpl< C... >, string_tpl<>)
Implementation of the function to parse a string.
Definition: pow_enum.hpp:54
String as a template of characters.
Definition: pow_enum.hpp:20
static constexpr char chars[sizeof...(C)+1]
Definition: pow_enum.hpp:21
Transform a template of characters into a string.
Definition: pow_enum.hpp:34
Helper struct to convert strings to templates of strings.
Definition: pow_enum.hpp:25
apply_range< count - 1, meta_functor, count - 1, indices... >::result result
Definition: pow_enum.hpp:36
Definition: pow_enum.hpp:26
Utilities to define smart enumeration types.
Definition: pow_enum.hpp:17
string_tpl< lambda_str_type{}.chars[indices]... > result
Definition: pow_enum.hpp:27
constexpr auto parse_string(string_tpl< C... > s)
Parse a string template and return it as an array of strings.
Definition: pow_enum.hpp:78