Magic Enum is a C++ library that provides compile-time reflection for enumerations, enabling conversion between enum values and their string names, iteration over enum members, and validation of enum values without relying on macros or external code generation. It uses template metaprogramming and constexpr functions to extract enum information directly from the compiler's internal representation, making the entire reflection process static and free of runtime overhead.
The library distinguishes itself through its comprehensive set of compile-time enum utilities, including the ability to count enum elements, iterate over all values, and dispatch runtime enum values to compile-time code paths via switch-like constructs. It also supports bitwise-combined enum flags, allowing flag combinations to be decomposed into individual components and mapped to their string names, as well as enum fusion, which encodes two enum values into a single integer for multi-level switch dispatch.
Beyond its core reflection capabilities, Magic Enum offers string parsing that converts string representations back into enum values with support for case-insensitive matching, integer-to-enum conversion with validity checking, and membership validation to determine whether a given value, integer, or string belongs to an enum's set of valid members. The library is header-only and requires no additional build steps or configuration to use.