Apply every section newer than your version. For example, from 0.9.5 apply 0.9.7, 0.9.8 and 0.10.0.
From 0.9.8. Review the behavior changes, then fix the compile errors.
Minimum versions: C++17, GCC 9, Clang 9, Xcode 11, MSVC 19.20 (Visual Studio 2019), CMake 3.22.
Options such as MAGIC_ENUM_NO_AUTO_IS_FLAGS and the range macros must match in every translation unit and in the module. Put them in one header and pass MAGIC_ENUM_CONFIG_FILE to the whole build.
These compile but can change counts, indices and names. Review stored indices, loops over enum_values and serialized names.
-
Automatic flags. An enum with
operator|andoperator&found by ADL and returning the enum is now reflected as flags. Only a named zero and named single bits are reflected. Streams, formatting and containers use flags too.To keep common reflection, set
is_flags = false, or defineMAGIC_ENUM_NO_AUTO_IS_FLAGSfor the whole build. Useas_common<>for a single call.template <> struct magic_enum::customize::enum_range<E> { static constexpr bool is_flags = false; }; static_assert(!magic_enum::is_flags_enum_v<E>); // Guards against a silent switch.
-
Named zero in flags.
None = 0is a regular flag value. It is counted and iterated,enum_flags_name(E{0})returns"None"instead of"", andenum_flags_cast("None")succeeds. DefineMAGIC_ENUM_NO_NAMED_ZERO_IN_FLAGSfor the whole build to leave it out. -
Signed flags also reflect the sign bit, first in value order.
-
C++26 reflection is selected automatically when available. It reflects only declared values, ignores the scan range and names aliases by their first declaration. Define
MAGIC_ENUM_FORCE_COMPILER_SPECIFIC_REFLECTIONto keep the previous backend. -
Checked integers. Casts and membership checks reject integers that do not fit the underlying type. For a
uint8_tenum,enum_cast<E>(257)is empty instead ofE{1}. Cast intentional narrowing explicitly, and passunsigned charinstead ofcharfor bytes above0x7F. -
Customization hooks are found only through ADL. A global
magic_enum_define_range_adlfor an enum in a namespace is ignored. Move it to the enum's namespace. -
Custom names rename or hide declared values only. A custom name for an undeclared value other than zero is ignored.
-
enum_switchreturns by value, even when the explicit result type is a reference. -
enum_reflectedaccepts only zero and single bits for flags, and any representable value of a common enum with standard reflection. The result no longer depends on whether values are reflected. -
Stream output writes unnamed values of enums with a character underlying type as numbers.
static_cast<E>(65)prints65instead ofA. -
Container comparators. Keys that compare equivalent keep
enum_valuesorder, so their indices can change.containers::setcompares lexicographically. -
containers::bitset. In strings, zero and combinations are masks, not positions.(sv, {})now passes a null character as the separator. Use(sv)for the default|separator.to_ulongreturnsunsigned long. Check stream state after input.
-
A named value has more than one bit set, for example
All = A | Bin an enum with ADL operators. Setis_flags = falseto keep 0.9 behavior and names, oris_flags = trueto reflect single bits only, seeenum_flags. If a namespace defines operator templates for all its enums, defineMAGIC_ENUM_NO_AUTO_IS_FLAGSfor the whole build.MAGIC_ENUM_NO_CHECK_MULTIBIT_FLAGSdisables only the check. -
A named value is just outside the scan range. Extend the range. To hide a sentinel such as
Count, returninvalid_tagfromcustomize::enum_name.MAGIC_ENUM_NO_CHECK_OUT_OF_RANGEdisables only the check. -
Bitwise operators are missing. Include
<magic_enum/magic_enum_bitwise.hpp>. PreferMAGIC_ENUM_DEFINE_BITWISE_OPERATORS(E)next to the enum, and keepusing namespace magic_enum::bitwise_operatorsinside functions. -
enum_range<E>::is_flagsis not set. Read the mode withis_flags_enum_v<E>. -
Explicit
E&inenum_contains,enum_reflectedandenum_flags_contains. Drop&or pass an lvalue. -
MAGIC_ENUM_NO_ASSERTtogether withMAGIC_ENUM_ASSERT. Define only one of them. -
customize_t. Replacefirstandsecondwithtagandname. It no longer inheritsstd::pair, so compare the fields and build astd::pairexplicitly if needed. -
A custom name for an undeclared zero. Declare the value, for example
None = 0. -
containers::set<E>(mask). Useset<E>::from_mask(mask). An invalid key throwsstd::invalid_argument. -
containers::bitsetstring constructor. The order is now(sv, sep, cmp). -
enum_type_namefor an unnamed enum. Give the enum a typedef name or specializecustomize::enum_type_name. -
Removed macros. Drop
MAGIC_ENUM_SUPPORTED_ALIASESchecks andMAGIC_ENUM_ENABLE_HASH_SWITCH.
Link magic_enum::magic_enum_module. magic_enum::magic_enum stays header-only. Modules need C++20 and CMake 3.28, see compiler issues.
From 0.9.7.
MAGIC_ENUM_AUTO_IS_FLAGSis removed and ignored. Setis_flags = truefor each enum that relied on it.enum_flags_castandenum_flags_containswith a predicate take the separator first:(sv, '|', p).MAGIC_ENUM_DEFAULT_ENABLE_ENUM_FORMATandcustomize::enum_format_enabledare removed. Fully specializestd::formatterorfmt::formatterfor one enum, or defineMAGIC_ENUM_NO_STD_FORMATorMAGIC_ENUM_NO_FMT_FORMATfor the whole build.
From 0.9.4, 0.9.5 or 0.9.6.
- Include
<magic_enum/magic_enum.hpp>instead of<magic_enum.hpp>. The CMake, Meson and Bazel targets addinclude, notinclude/magic_enum, to the include path.
From 0.8.x or an earlier 0.9.x. Headers were split and moved. <magic_enum/magic_enum_all.hpp> includes all of them.
- 0.9.4: headers moved from
include/toinclude/magic_enum/. - 0.9.3:
enum_for_eachmoved tomagic_enum_utility.hpp. - 0.9.2:
enum_flags_*functions moved tomagic_enum_flags.hpp. - 0.9.0: stream operators moved to
magic_enum_iostream.hpp.