Celeritas
0.5.0-56+6b053cd
|
Map strings to enums for user input. More...
#include <StringEnumMapper.hh>
Public Types | |
Type aliases | |
using | EnumCStringFuncPtr = char const *(T) |
Public Member Functions | |
template<class U > | |
StringEnumMapper (U &&enum_to_string, char const *desc=nullptr) | |
Construct with a "stringify" function. More... | |
T | operator() (std::string_view s) const |
Convert a string_view to the corresponding enum. | |
Static Public Member Functions | |
static StringEnumMapper< T > | from_cstring_func (EnumCStringFuncPtr, char const *desc=nullptr) |
Construct using a to_cstring function. | |
Map strings to enums for user input.
Note that since a map is built at construction time, instances of this class should be static
to amortize the cost. The strings being converted must exceed the lifetime of this class. (Usually it references const char*
.)
Example:
|
inlineexplicit |
Construct with a "stringify" function.
The result just has to be implicitly convertible to a std::string_view
.