Skip to content

Add min_value_of / max_value_of / to_underlying to meta enum

Gerhard Raven requested to merge add-min-max-to-meta_enum into 2024-patches

Add a way to obtain the minimum and maximum values of an enum defined using meta_enum:

   constexpr MyEnum min_value = min_value_of<MyEnum>();
   constexpr MyEnum max_value = max_value_of<MyEnum>();

Also add a way to get the underlying value, conform C++23 std::to_underlying, i.e.

   meta_enum_class_with_unknown( MyEnum2, int, A, B, C )
   auto a = to_underlying( MyEnum2::A );

   static_assert( std::is_same_v< int, decltype(a) > );

requires Rec!3978 (merged) to suppress a build warning with clang

Edited by Christopher Rob Jones

Merge request reports