Skip to content

Provide programatic access to enum class metadata

License

Notifications You must be signed in to change notification settings

jhashkes/enum_class

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C++ Enum Class

Features

  • 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"

Remarks

Integration

Compiler compatibility

Licensed under the MIT License

About

Provide programatic access to enum class metadata

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published