magic_enum provides constexpr conversion between enum values and strings without macros or extra metadata. It ships as a single-header style library with optional C++20 module builds.
Overview
magic_enum is a C++ header-only library that reflects enum value names at compile time using static reflection techniques. It can format enums for logging, parse strings back to values, and expose flag and switch helpers through additional headers.
The project documents compiler support for recent Clang, GCC, MSVC, and Xcode releases, with automatic use of C++26 reflection when available. CMake targets include header-only magic_enum and an optional magic_enum module built with MAGIC_ENUM_USE_MODULES.
Utilities cover enum ranges, bitwise operators, containers adapters, and verification targets to ensure each header compiles in isolation. pkg-config installs expose only the header-only target.
Consumers copy headers or link the CMake targets without runtime dependencies beyond the standard library.
Key features
- Compile-time enum-to-string and string-to-enum
- Header-only distribution with CMake targets
- Optional C++20 module build
- Flag, switch, and container helper headers
- Verified public headers via interface target
- Supports major Clang, GCC, and MSVC releases
Use cases
- Log human-readable enum names in C++ services
- Parse configuration strings into enum values
- Generate switch tables without manual maintenance