Header-only C++17 library providing compile-time enum reflection
README
ofxMagicEnum
// _ __ _
// | \/ | (_) | __| / __|_ _
// | \ / | _ _ _ _ | | _ _ _ _ ___ | | _| |_ _| |_
// | |\/| |/ _ |/ _ | |/ | | | | '_ \| | | | '_ _ \ | | |_ _|_ _|
// | | | | (_| | (_| | | ( | || | | | |_| | | | | | | | |__|_| |_|
// |_| |_|\,_|\, |_|\_| |__|_| |_|\,_|_| |_| |_| \_|
// __/ | https://github.com/Neargye/magic_enum
// |___/ version 0.9.7A thin wrapper addon for magic_enum v0.9.7 — a header-only C++17 library providing compile-time enum reflection.
Features
- magic_enum::enum_name(value)
— enum value → string - magic_enum::enum_cast<E>("name")
— string → enum value (returnsstd::optional) - magic_enum::enum_values<E>()
— iterate all values at compile time - magic_enum::enum_type_name<E>()
— enum type name as a string - Flags support, containers, switch helpers, iostream integration (via magic_enum_all.hpp
)
Usage
Add ofxMagicEnum
to your addons.make, then include what you need:
// Core reflection only
include <magic_enum/magic_enum.hpp>
// Everything (flags, containers, switch, iostream helpers)
include <magic_enum/magic_enum_all.hpp>
Example
enum class Direction { North, South, East, West };
auto name = magic_enum::enum_name(Direction::North); // "North"
auto val = magic_enum::enum_cast<Direction>("East"); // std::optional<Direction>
for (auto v : magic_enum::enum_values<Direction>()) {
ofLog() << magic_enum::enum_name(v);
}
MIT — see include/magic_enum/magic_enum.hpp` header.
ofxAddons