Skip to content

Magic Enum v0.10.0

Latest

Choose a tag to compare

@Neargye Neargye released this 25 Nov 14:23

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| and operator& returning the enum is now reflected as flags. Names, counts and indices can change, and named combinations can fail to compile. Set is_flags = false for one enum or define MAGIC_ENUM_NO_AUTO_IS_FLAGS for 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_REFLECTION to keep the previous backend.
  • Validation: integer lookups reject values outside the underlying type, for example enum_cast<E>(257) for a uint8_t enum 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-bool is_flags, std::format of std::byte with MAGIC_ENUM_NO_CHECK_REFLECTED_ENUM, and both MAGIC_ENUM_NO_ASSERT and MAGIC_ENUM_ASSERT defined.
  • Bitwise operators: magic_enum.hpp no longer provides them, include magic_enum_bitwise.hpp.
  • Customization: ADL hooks must be declared in the enum's namespace. adl_info() leaves flags detection automatic, read the mode with is_flags_enum_v<E> instead of enum_range<E>::is_flags. customize_t has tag and name fields instead of inheriting std::pair.
  • Containers: set<E>(mask) is now set<E>::from_mask(mask). The bitset string constructor is now (sv, sep, cmp), and for flags, zero and combinations are masks, not positions. Equivalent keys keep enum_values order, so stored indices can change. set throws 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_as overload is formatted by it (#485).
  • Module: {fmt} support is no longer detected automatically. Set MAGIC_ENUM_MODULE_WITH_FMT=ON, or define MAGIC_ENUM_USE_FMT_HEADER when building the module without CMake.
  • Removed macros: MAGIC_ENUM_SUPPORTED_ALIASES, MAGIC_ENUM_ENABLE_HASH_SWITCH.

New features

  • enum_min and enum_max return the minimum and maximum reflected values (#462).
  • is_flags_enum and is_flags_enum_v report the default mode (#447).
  • MAGIC_ENUM_DEFINE_BITWISE_OPERATORS(E) and MAGIC_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_FORMAT and MAGIC_ENUM_NO_FMT_FORMAT.
  • Custom string results for enum_flags_name and bitset::to_string, with constexpr support when the string type allows it (#152).
  • bitset iterators, find, flip(pos) and std::hash (#393, #450).
  • CMake target magic_enum::magic_enum_module with optional import std and {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_fuse overflow.
  • 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.hpp of another release (#420).