diff --git a/include/magic_enum.hpp b/include/magic_enum.hpp index 7508fc7..8f7b215 100644 --- a/include/magic_enum.hpp +++ b/include/magic_enum.hpp @@ -90,8 +90,8 @@ struct supported final : std::false_type {}; #endif -template -inline constexpr bool is_enum_v = std::is_enum_v && std::is_same_v>; +template +inline constexpr bool is_enum_v = std::is_enum_v && std::is_same_v>; template struct static_string final { @@ -263,7 +263,7 @@ constexpr auto values(std::integer_sequence) noexcept { std::array> values{}; for (std::size_t i = 0, v = 0; v < count_v; ++i) { if (valid[i]) { - values[v++] = static_cast(static_cast(i) + min_v); + values[v++] = static_cast(i + min_v); } } @@ -303,10 +303,6 @@ constexpr auto entries(std::index_sequence) noexcept { template using enable_if_enum_t = std::enable_if_t>, R>; -} // namespace magic_enum::detail - -namespace traits { - template > struct is_scoped_enum : std::false_type {}; @@ -329,32 +325,32 @@ template struct enum_traits {}; template -struct enum_traits>> { +struct enum_traits>> { using type = E; using underlying_type = std::underlying_type_t; inline static constexpr std::string_view type_name = detail::type_name_v; - inline static constexpr bool is_unscoped_enum = traits::is_unscoped_enum::value; - inline static constexpr bool is_scoped_enum = traits::is_scoped_enum::value; + inline static constexpr bool is_unscoped_enum = detail::is_unscoped_enum::value; + inline static constexpr bool is_scoped_enum = detail::is_scoped_enum::value; inline static constexpr std::size_t count = detail::count_v; - inline static constexpr std::array values = detail::values(detail::range_v); - inline static constexpr std::array names = detail::names(detail::sequence_v); - inline static constexpr std::array, count> entries = detail::entries(detail::sequence_v); + inline static constexpr std::array values = detail::values(range_v); + inline static constexpr std::array names = detail::names(sequence_v); + inline static constexpr std::array, count> entries = detail::entries(sequence_v); [[nodiscard]] static constexpr bool reflected(E value) noexcept { - return static_cast(value) >= static_cast(detail::reflected_min_v) && static_cast(value) <= static_cast(detail::reflected_max_v); + return static_cast(value) >= static_cast(reflected_min_v) && static_cast(value) <= static_cast(reflected_max_v); } [[nodiscard]] static constexpr int index(E value) noexcept { - if (static_cast(value) >= static_cast(detail::min_v) && static_cast(value) <= static_cast(detail::max_v)) { - if constexpr (detail::size_v != detail::count_v) { - if (auto i = indexes[static_cast(value) - detail::min_v]; i != detail::invalid_index_v) { + if (static_cast(value) >= static_cast(min_v) && static_cast(value) <= static_cast(max_v)) { + if constexpr (size_v != count_v) { + if (auto i = indexes[static_cast(value) - min_v]; i != invalid_index_v) { return i; } } else { - return static_cast(value) - detail::min_v; + return static_cast(value) - min_v; } } @@ -362,10 +358,10 @@ struct enum_traits>> { } [[nodiscard]] static constexpr E value(std::size_t index) noexcept { - if constexpr (detail::size_v != detail::count_v) { + if constexpr (size_v != count_v) { return assert(index < count), values[index]; } else { - return assert(index < count), static_cast(detail::min_v + index); + return assert(index < count), static_cast(index + min_v); } } @@ -383,10 +379,10 @@ struct enum_traits>> { static_assert(enum_range::max > enum_range::min, "magic_enum::enum_range requires max > min."); static_assert(count > 0, "magic_enum::enum_range requires enum implementation or valid max and min."); using U = underlying_type; - inline static constexpr auto indexes = detail::indexes(detail::range_v); + inline static constexpr auto indexes = detail::indexes(range_v); }; -} // namespace magic_enum::traits +} // namespace magic_enum::detail // Checks is magic_enum supported compiler. inline constexpr bool is_magic_enum_supported = detail::supported::value; @@ -394,7 +390,7 @@ inline constexpr bool is_magic_enum_supported = detail::supported::value; // Checks whether T is an Unscoped enumeration type. // Provides the member constant value which is equal to true, if T is an [Unscoped enumeration](https://en.cppreference.com/w/cpp/language/enum#Unscoped_enumeration) type. Otherwise, value is equal to false. template -struct is_unscoped_enum : traits::is_unscoped_enum {}; +struct is_unscoped_enum : detail::is_unscoped_enum {}; template inline constexpr bool is_unscoped_enum_v = is_unscoped_enum::value; @@ -402,7 +398,7 @@ inline constexpr bool is_unscoped_enum_v = is_unscoped_enum::value; // Checks whether T is an Scoped enumeration type. // Provides the member constant value which is equal to true, if T is an [Scoped enumeration](https://en.cppreference.com/w/cpp/language/enum#Scoped_enumerations) type. Otherwise, value is equal to false. template -struct is_scoped_enum : traits::is_scoped_enum {}; +struct is_scoped_enum : detail::is_scoped_enum {}; template inline constexpr bool is_scoped_enum_v = is_scoped_enum::value; @@ -410,14 +406,14 @@ inline constexpr bool is_scoped_enum_v = is_scoped_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 : traits::underlying_type {}; +struct underlying_type : detail::underlying_type {}; template using underlying_type_t = typename underlying_type::type; // Enum traits defines a compile-time template-based interface to query the properties of enum. template -using enum_traits = traits::enum_traits>; +using enum_traits = detail::enum_traits>; // Obtains enum value from enum string name. // Returns std::optional with enum value.