46template <
typename Enum,
typename Derived>
60 static std::string
str(Enum e) {
61 return Derived::mapping().at(e);
76 static Enum
enum_elt(
const std::string& name) {
77 return Derived::inverse_mapping().at(name);
88 static std::vector<std::string>
get_str() {
89 std::vector<std::string> out;
90 for (
const auto& [key, val] : Derived::mapping()) {
105 std::vector<Enum> out;
106 for (
const auto& [key, val] : Derived::mapping()) {
130template <
typename K,
typename V>
133 for (
const auto& [k, v] : original) {
std::map< V, K > invert_map(const std::map< K, V > &original)
Builds the inverse of a std::map by swapping keys and values.
CRTP base class for enum–string mappers.
static std::vector< std::string > get_str()
Returns all string representations defined in the mapping.
static Enum enum_elt(const std::string &name)
Returns the enum value associated to a given string.
static std::string str(Enum e)
Returns the string representation of an enum value.
static std::vector< Enum > get_enum()
Returns all enum values defined in the mapping.