Magic Enum is a header-only C++17 library that provides static reflection for enums, enabling conversion between enum values and strings, iteration, and type introspection without requiring macros or boilerplate code.
The library solves the problem of working with enums in C++ where standard language features offer no built-in way to convert between enum values and their string representations or to iterate over enum members. Magic Enum uses compile-time metaprogramming to reflect on enum types and generate the necessary conversion and introspection functions automatically. It requires only that you include the appropriate header and call the library's functions on your enum type; no registration, annotation, or code generation step is needed.
The tool suits any C++ project that needs to serialize enums to strings, parse strings back to enum values, or perform runtime operations like iteration or membership testing on enum types. It works with both scoped and unscoped enums and supports flag operations for bitwise enum types. The library integrates into existing build systems through CMake, vcpkg, Conan, Build2, Meson, Bazel, and ROS, and can be used as a header-only library or as a C++20 module. Developers should be aware of the enum range limitation documented in the project's limitations section, though compile-time enum-to-string conversion is available as an alternative that avoids this restriction.
The project maintains active development with regular updates addressing compiler compatibility and feature requests. The codebase supports a wide range of compiler versions including GCC 9 and later, Clang 5 and later, MSVC 2017 and later, and Xcode 10 and later. The library provides extensive integration options and optional features such as formatting support through the fmt library and C++20 module support with configurable standard library imports.