This commit is contained in:
terik23 2019-04-09 02:52:00 +05:00
parent fd60c11a50
commit 8df003ea53

View file

@ -195,7 +195,7 @@ template <typename E, E V>
template <typename E, int O, int... I> template <typename E, int O, int... I>
[[nodiscard]] constexpr decltype(auto) enum_strings_impl(std::integer_sequence<int, I...>) noexcept { [[nodiscard]] constexpr decltype(auto) enum_strings_impl(std::integer_sequence<int, I...>) noexcept {
static_assert(std::is_enum_v<E>, "magic_enum::detail::enum_strings_impl requires enum type."); static_assert(std::is_enum_v<E>, "nameof::detail::enum_strings_impl requires enum type.");
constexpr std::array<std::string_view, sizeof...(I)> enum_names{{enum_name_impl<E, static_cast<E>(I + O)>()...}}; constexpr std::array<std::string_view, sizeof...(I)> enum_names{{enum_name_impl<E, static_cast<E>(I + O)>()...}};
return enum_names; return enum_names;
@ -203,9 +203,10 @@ template <typename E, int O, int... I>
template <typename E, typename U = std::underlying_type_t<E>> template <typename E, typename U = std::underlying_type_t<E>>
[[nodiscard]] constexpr std::string_view nameof_enum_impl(int value) noexcept { [[nodiscard]] constexpr std::string_view nameof_enum_impl(int value) noexcept {
static_assert(std::is_enum_v<E>, "magic_enum::detail::nameof_enum_impl requires enum type."); static_assert(std::is_enum_v<E>, "nameof::detail::nameof_enum_impl requires enum type.");
constexpr int max = (enum_range<E>::max < std::numeric_limits<U>::max()) ? enum_range<E>::max : std::numeric_limits<U>::max(); static_assert(enum_range<E>::max > enum_range<E>::min, "nameof::enum_range requires max > min.");
constexpr int min = (enum_range<E>::min > std::numeric_limits<U>::min()) ? enum_range<E>::min : std::numeric_limits<U>::min(); constexpr int max = enum_range<E>::max < (std::numeric_limits<U>::max)() ? enum_range<E>::max : (std::numeric_limits<U>::max)();
constexpr int min = enum_range<E>::min > (std::numeric_limits<U>::min)() ? enum_range<E>::min : (std::numeric_limits<U>::min)();
constexpr auto enum_range = std::make_integer_sequence<int, max - min + 1>{}; constexpr auto enum_range = std::make_integer_sequence<int, max - min + 1>{};
constexpr auto enum_names = enum_strings_impl<E, min>(enum_range); constexpr auto enum_names = enum_strings_impl<E, min>(enum_range);
const int i = value - min; const int i = value - min;
@ -230,8 +231,8 @@ template <typename T>
} // namespace detail } // namespace detail
// Obtains simple (unqualified) string enum name of enum variable. // Obtains simple (unqualified) string enum name of enum variable.
template <typename T, typename D = std::decay_t<T>, typename = std::enable_if_t<std::is_enum_v<D>>> template <typename E, typename D = std::decay_t<E>, typename = std::enable_if_t<std::is_enum_v<D>>>
[[nodiscard]] constexpr std::string_view nameof_enum(T value) noexcept { [[nodiscard]] constexpr std::string_view nameof_enum(E value) noexcept {
static_assert(std::is_enum_v<D>, "nameof::nameof_enum requires enum type."); static_assert(std::is_enum_v<D>, "nameof::nameof_enum requires enum type.");
return detail::nameof_enum_impl<D>(static_cast<int>(value)); return detail::nameof_enum_impl<D>(static_cast<int>(value));