- C++17
- Header-only
- Dependency-free
- Enum to string
- String to enum
- Retrieve sequence of Enum values or names
ENUM_CLASS(Animal, int,
CAT = -5, DOG, HORSE = 7);
-
Enum value to string
Access enum class metadata using enum_class namespace functions:
auto animal_str = enum_class::Name(Animal::DOG); // no need to specify <Animal> // animal_str == "DOG"
Alternative method using automatically generated meta class:
auto animal_str = AnimalMeta::Name(Animal::DOG); // animal_str == "DOG"
-
String to enum value
Access enum class metadata using enum_class namespace functions:
auto animal = enum_class::Value<Animal>("HORSE"); // need to specify <Animal> if (animal) { // *animal == Animal::HORSE }
Alternative method using automatically generated meta class:
auto animal = AnimalMeta::Value("HORSE"); // no need to specify <Animal> if (animal) { // *animal == Animal::HORSE }
-
Enum values sequence
auto animals = enum_class::Values<Animal>(); // animals == { Animal::CAT, Animal::DOG, Animal::HORSE } // animals[0] == Animal::CAT
-
Enum names sequence
auto animal_names = enum_class::Names<Animal>(); // animal_names == { "CAT", "DOG", "HORSE" } // animal_names[0] == "CAT"
- Include enum_class.hpp.