Repository navigation
v0.10.0
See the migration guide for upgrade steps and compatibility options.
Breaking changes
- Minimum versions: C++17, GCC 9, Clang 9, Xcode 11, MSVC 19.20 / Visual Studio 2019, CMake 3.22, ReSharper C++ and CLion Nova 2025.3.
- Automatic flags: an enum with ADL
operator|andoperator&returning the enum is now reflected as flags. Names, counts and indices can change, and named combinations can fail to compile. Setis_flags = falsefor one enum or defineMAGIC_ENUM_NO_AUTO_IS_FLAGSfor the whole build, see flags limitations. - Flag values: flags include a named zero and the sign bit of signed enums (#321, #378). Zero participates in counts and iteration, and its name is used for formatting and parsing.
- C++26 standard reflection: used automatically when available. It ignores the scan range and uses the first declared name for aliases, so counts, indices and names can change. Define
MAGIC_ENUM_FORCE_COMPILER_SPECIFIC_REFLECTIONto keep the previous backend. - Validation: integer lookups reject values outside the underlying type, for example
enum_cast<E>(257)for auint8_tenum is empty. Name customization can rename or hide declared values, but not add them. - New compile errors: some named values just outside the scan range, non-integer arguments, explicit
E&with rvalues, a custom name for an undeclared zero, a non-boolis_flags,std::formatofstd::bytewithMAGIC_ENUM_NO_CHECK_REFLECTED_ENUM, and bothMAGIC_ENUM_NO_ASSERTandMAGIC_ENUM_ASSERTdefined. - Bitwise operators:
magic_enum.hppno longer provides them, includemagic_enum_bitwise.hpp. - Customization: ADL hooks must be declared in the enum's namespace.
adl_info()leaves flags detection automatic, read the mode withis_flags_enum_v<E>instead ofenum_range<E>::is_flags.customize_thastagandnamefields instead of inheritingstd::pair. - Containers:
set<E>(mask)is nowset<E>::from_mask(mask). Thebitsetstring constructor is now(sv, sep, cmp), and for flags, zero and combinations are masks, not positions. Equivalent keys keepenum_valuesorder, so stored indices can change.setthrows for unknown values and compares lexicographically. enum_switch: returns results by value, also for reference result types (#477).enum_type_name: unnamed enums need a typedef name or name customization (#128).enum_reflected: checks whether a value can be reflected at all, regardless of its name: within the scan range for common enums, any representable value with standard reflection, and zero or a single bit for flags.- Output: unnamed values with a character underlying type are streamed as numbers. With fmt, an enum with its own
format_asoverload is formatted by it (#485). - Module:
{fmt}support is no longer detected automatically. SetMAGIC_ENUM_MODULE_WITH_FMT=ON, or defineMAGIC_ENUM_USE_FMT_HEADERwhen building the module without CMake. - Removed macros:
MAGIC_ENUM_SUPPORTED_ALIASES,MAGIC_ENUM_ENABLE_HASH_SWITCH.
New features
enum_minandenum_maxreturn the minimum and maximum reflected values (#462).is_flags_enumandis_flags_enum_vreport the default mode (#447).MAGIC_ENUM_DEFINE_BITWISE_OPERATORS(E)andMAGIC_ENUM_DEFINE_IOSTREAM_OPERATORS(E)define operators for one enum (#434). Friend variants cover private nested enums and class templates.- Options for the whole build:
MAGIC_ENUM_NO_AUTO_IS_FLAGS,MAGIC_ENUM_NO_NAMED_ZERO_IN_FLAGS,MAGIC_ENUM_NO_CHECK_OUT_OF_RANGE,MAGIC_ENUM_NO_CHECK_MULTIBIT_FLAGS,MAGIC_ENUM_REQUIRE_STD_REFLECTION,MAGIC_ENUM_NO_STD_FORMATandMAGIC_ENUM_NO_FMT_FORMAT. - Custom string results for
enum_flags_nameandbitset::to_string, with constexpr support when the string type allows it (#152). bitsetiterators,find,flip(pos)andstd::hash(#393, #450).- CMake target
magic_enum::magic_enum_modulewith optionalimport stdand{fmt}integration (#455, #465, #487). Needs C++20, CMake 3.28 and a supported compiler. It exports the C++ API, but not macros, see module setup. - NVCC and NVC++ support (#371), see limitations.
Fixes and improvements
- Optimized compilation time, memory use and flag lookup.
- Fixed lookup and bitwise operators for enums with a bool underlying type, duplicate name lookup, callable handling (#459), navigation and
enum_fuseoverflow. - Fixed enums in class templates on Clang (#65, #164, #296), enum names in templated lambdas on GCC 13 to 15 (#452) and flag name parsing in optimized GCC C++26 builds (#467).
- Fixed container bounds checks, ordering, insertion, erasure and iteration.
- Fixed formatting and streams for enums with no reflected values, stream width (#479, #480), failed stream input, fmt 12 byte formatting and fmt 9 with
format_as(#485). - Improved compiler and module compatibility (#461, #475), CMake installation, packaging from a subproject (#418) and pkg-config metadata.
- Extension headers fail with a clear error when they find a
magic_enum.hppof another release (#420).