diff --git a/include/nameof.hpp b/include/nameof.hpp index a2cfdf8..6fef869 100644 --- a/include/nameof.hpp +++ b/include/nameof.hpp @@ -193,24 +193,21 @@ template #endif } -template +template [[nodiscard]] constexpr decltype(auto) enum_strings_impl(std::integer_sequence) noexcept { static_assert(std::is_enum_v, "magic_enum::detail::enum_strings_impl requires enum type."); - using U = std::underlying_type_t; - constexpr int min = (enum_range::min > std::numeric_limits::min()) ? enum_range::min : std::numeric_limits::min(); - constexpr std::array enum_names{{enum_name_impl(I + min)>()...}}; + constexpr std::array enum_names{{enum_name_impl(I + O)>()...}}; return enum_names; } -template +template > [[nodiscard]] constexpr std::string_view nameof_enum_impl(int value) noexcept { static_assert(std::is_enum_v, "magic_enum::detail::nameof_enum_impl requires enum type."); - using U = std::underlying_type_t; constexpr int max = (enum_range::max < std::numeric_limits::max()) ? enum_range::max : std::numeric_limits::max(); constexpr int min = (enum_range::min > std::numeric_limits::min()) ? enum_range::min : std::numeric_limits::min(); constexpr auto enum_range = std::make_integer_sequence{}; - constexpr auto enum_names = enum_strings_impl(enum_range); + constexpr auto enum_names = enum_strings_impl(enum_range); const int i = value - min; if (i >= 0 && static_cast(i) < enum_names.size()) { @@ -233,9 +230,11 @@ template } // namespace detail // Obtains simple (unqualified) string enum name of enum variable. -template >>> +template , typename = std::enable_if_t>> [[nodiscard]] constexpr std::string_view nameof_enum(T value) noexcept { - return detail::nameof_enum_impl>(static_cast(value)); + static_assert(std::is_enum_v, "nameof::nameof_enum requires enum type."); + + return detail::nameof_enum_impl(static_cast(value)); } // Obtains string name of type.