diff --git a/include/magic_enum.hpp b/include/magic_enum.hpp index 30200de..c66ebcb 100644 --- a/include/magic_enum.hpp +++ b/include/magic_enum.hpp @@ -220,6 +220,11 @@ constexpr auto n() noexcept { template inline constexpr auto name_v = n(); +template +constexpr bool is_valid() noexcept { + return n(V)>().size() != 0; +} + template constexpr std::size_t range_size() noexcept { static_assert(is_enum_v, "magic_enum::detail::range_size requires enum type."); @@ -259,7 +264,7 @@ inline constexpr int reflected_max_v = reflected_max(); template constexpr auto values(std::integer_sequence) noexcept { static_assert(is_enum_v, "magic_enum::detail::values requires enum type."); - constexpr std::array valid{{(n(I + reflected_min_v)>().size() != 0)...}}; + constexpr std::array valid{{is_valid>()...}}; constexpr int count = ((valid[I] ? 1 : 0) + ...); std::array values{}; @@ -296,9 +301,9 @@ inline constexpr auto invalid_index_v = (std::numeric_limits>::max)() template constexpr auto indexes(std::integer_sequence) noexcept { static_assert(is_enum_v, "magic_enum::detail::indexes requires enum type."); - index_t i = 0; + [[maybe_unused]] index_t i = 0; - return std::array, sizeof...(I)>{{((n(I + min_v)>().size() != 0) ? i++ : invalid_index_v)...}}; + return std::array, sizeof...(I)>{{(is_valid>() ? i++ : invalid_index_v)...}}; } template @@ -457,7 +462,9 @@ template // This version is much lighter on the compile times and is not restricted to the enum_range limitation. template [[nodiscard]] constexpr auto enum_name() noexcept -> detail::enable_if_enum_t { - constexpr std::string_view name = detail::name_v, V>; + 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>; static_assert(name.size() > 0, "Enum value does not have a name."); return name;