diff --git a/include/magic_enum.hpp b/include/magic_enum.hpp index 2df8bc6..ad1d968 100644 --- a/include/magic_enum.hpp +++ b/include/magic_enum.hpp @@ -32,6 +32,10 @@ #ifndef NEARGYE_MAGIC_ENUM_HPP #define NEARGYE_MAGIC_ENUM_HPP +#define MAGIC_ENUM_VERSION_MAJOR 0 +#define MAGIC_ENUM_VERSION_MINOR 6 +#define MAGIC_ENUM_VERSION_PATCH 6 + #include #include #include @@ -188,14 +192,16 @@ constexpr bool cmp_less(L lhs, R rhs) noexcept { } } -template +#if defined(NEARGYE_NAMEOF_HPP) +using ::nameof::detail::type_name_v; +#else +template constexpr auto n() noexcept { - static_assert(is_enum_v, "magic_enum::detail::n requires enum type."); -#if defined(MAGIC_ENUM_SUPPORTED) && MAGIC_ENUM_SUPPORTED +#if defined(__clang__) && __clang_major__ >= 5 || defined(__GNUC__) && __GNUC__ >= 7 || defined(_MSC_VER) && _MSC_VER >= 1910 # if defined(__clang__) - constexpr std::string_view name{__PRETTY_FUNCTION__ + 34, sizeof(__PRETTY_FUNCTION__) - 36}; + constexpr std::string_view name{__PRETTY_FUNCTION__ + 35, sizeof(__PRETTY_FUNCTION__) - 38}; # elif defined(__GNUC__) - constexpr std::string_view name{__PRETTY_FUNCTION__ + 49, sizeof(__PRETTY_FUNCTION__) - 51}; + constexpr std::string_view name{__PRETTY_FUNCTION__ + 50, sizeof(__PRETTY_FUNCTION__) - 53}; # elif defined(_MSC_VER) constexpr std::string_view name{__FUNCSIG__ + 40, sizeof(__FUNCSIG__) - 57}; # endif @@ -205,9 +211,13 @@ constexpr auto n() noexcept { #endif } -template -inline constexpr auto type_name_v = n(); +template +inline constexpr auto type_name_v = n(); +#endif +#if defined(NEARGYE_NAMEOF_HPP) +using ::nameof::detail::enum_name_v; +#else template constexpr auto n() noexcept { static_assert(is_enum_v, "magic_enum::detail::n requires enum type."); @@ -224,7 +234,8 @@ constexpr auto n() noexcept { } template -inline constexpr auto name_v = n(); +inline constexpr auto enum_name_v = n(); +#endif template constexpr bool is_valid() noexcept { @@ -321,7 +332,7 @@ template constexpr auto names(std::index_sequence) noexcept { static_assert(is_enum_v, "magic_enum::detail::names requires enum type."); - return std::array{{name_v[I]>...}}; + return std::array{{enum_name_v[I]>...}}; } template @@ -331,7 +342,7 @@ template constexpr auto entries(std::index_sequence) noexcept { static_assert(is_enum_v, "magic_enum::detail::entries requires enum type."); - return std::array, sizeof...(I)>{{{values_v[I], name_v[I]>}...}}; + return std::array, sizeof...(I)>{{{values_v[I], enum_name_v[I]>}...}}; } template @@ -472,7 +483,7 @@ template [[nodiscard]] constexpr auto enum_name() noexcept -> detail::enable_if_enum_t { using D = std::decay_t; static_assert(detail::supported::value, "magic_enum unsupported compiler (https://github.com/Neargye/magic_enum#compiler-compatibility)."); - constexpr std::string_view name = detail::name_v, V>; + constexpr std::string_view name = detail::enum_name_v, V>; static_assert(name.size() > 0, "Enum value does not have a name."); return name;