From 6fb880356c083116da552c05a52d578af1aefda8 Mon Sep 17 00:00:00 2001 From: neargye Date: Thu, 11 Jul 2019 20:23:21 +0500 Subject: [PATCH] add enum traits --- include/magic_enum.hpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/include/magic_enum.hpp b/include/magic_enum.hpp index 7d9d6a8..a4ddd4d 100644 --- a/include/magic_enum.hpp +++ b/include/magic_enum.hpp @@ -205,6 +205,18 @@ struct is_unscoped_enum_impl : std::false_type {}; template struct is_unscoped_enum_impl : std::bool_constant>> {}; +template +struct is_fixed_enum_impl : std::false_type {}; + +template +struct is_fixed_enum_impl : std::is_enum {}; + +template > +struct underlying_type_impl {}; + +template +struct underlying_type_impl : std::underlying_type {}; + } // namespace magic_enum::detail // Checks whether T is an Unscoped enumeration type. @@ -223,6 +235,22 @@ struct is_scoped_enum : detail::is_scoped_enum_impl {}; template inline constexpr bool is_scoped_enum_v = is_scoped_enum::value; +// Checks whether T is an Fixed enumeration type. +// Provides the member constant value which is equal to true, if T is an [Fixed enumeration](https://en.cppreference.com/w/cpp/language/enum) type. Otherwise, value is equal to false. +template +struct is_fixed_enum : detail::is_fixed_enum_impl {}; + +template +inline constexpr bool is_fixed_enum_v = is_fixed_enum::value; + +// If T is a complete enumeration type, provides a member typedef type that names the underlying type of T. +// Otherwise, if T is not an enumeration type, there is no member type. Otherwise (T is an incomplete enumeration type), the program is ill-formed. +template +struct underlying_type : detail::underlying_type_impl {}; + +template +using underlying_type_t = typename underlying_type::type; + // Obtains enum value from enum string name. // Returns std::optional with enum value. template >