16template <
typename Enum>
19 using Entry = pair<Enum, string>;
23 [[nodiscard]]
const string&
to_string(Enum value)
const
25 for (
const auto& [enum_value, name] :
entries)
26 if (enum_value == value)
28 throw runtime_error(
"Unknown enum value");
33 for (
const auto& [enum_value, entry_name] :
entries)
34 if (entry_name == name)
36 throw runtime_error(format(
"Unknown enum string: {}", name));
39 [[nodiscard]] Enum
from_string(
const string& name, Enum fallback)
const
41 for (
const auto& [enum_value, entry_name] :
entries)
42 if (entry_name == name)
Definition adaptive_moment_estimation.h:14
Enum from_string(const string &name, Enum fallback) const
Definition enum_map.h:39
const string & to_string(Enum value) const
Definition enum_map.h:23
const vector< Entry > & entries
Definition enum_map.h:21
Enum from_string(const string &name) const
Definition enum_map.h:31
pair< Enum, string > Entry
Definition enum_map.h:19