Header-only C++17 library providing static reflection for enums without macros or boilerplate code.
Magic Enum is a header-only C++17 library that provides static reflection capabilities for enumeration types. It solves the common problem of converting enums to strings, iterating over enum values, and performing reverse lookups without requiring macros or repetitive code. The library works with any enum type, including scoped and unscoped enums, offering a clean and type-safe API.
C++ developers working with enumeration types who need robust utilities for serialization, debugging, UI rendering, or configuration handling. It's particularly useful for projects that involve logging, data validation, or enum-driven logic.
Developers choose Magic Enum because it eliminates boilerplate code, requires no macros, and provides a comprehensive set of utilities out of the box. Its header-only design and compatibility with modern C++ make it easy to integrate, while its focus on compile-time operations ensures zero runtime overhead.
Static reflection for enums (to string, from string, iteration) for modern C++, work with any enum type without any macro or boilerplate code
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
As a header-only library, it requires no separate compilation and integrates seamlessly with any C++17 project via package managers like Conan or vcpkg, reducing build complexity.
Provides out-of-the-box functions for name conversion, iteration, flag handling, and container support, covering most common enum operations without boilerplate code or macros.
Operations like enum_name and enum_values are evaluated at compile-time, ensuring no performance penalty at runtime, which is ideal for performance-critical applications.
Works without macros, offering a cleaner and more maintainable API compared to alternatives that rely on preprocessor tricks, as evidenced by the straightforward include and usage examples.
The library is optimized for small enums and has hard constraints on the number of values and underlying type ranges, requiring users to manually adjust enum_range for larger or non-standard enums, as detailed in the limitations document.
Requires C++17 and specific compiler versions (e.g., GCC >= 9), which can be a barrier for legacy projects or environments with restricted toolchains, limiting adoption in older codebases.
For enums with many values or complex flag operations, the template-heavy implementation can significantly increase compilation times, a trade-off acknowledged in the remarks about being designed for small enums.