diff --git a/include/nameof.hpp b/include/nameof.hpp index 3de1b67..547080b 100644 --- a/include/nameof.hpp +++ b/include/nameof.hpp @@ -559,26 +559,39 @@ constexpr auto n() noexcept { template inline constexpr auto enum_name_v = n(); -template -constexpr bool is_valid() noexcept { +template +constexpr bool valid() noexcept { static_assert(is_enum_v, "nameof::detail::is_valid requires enum type."); return n(V)>().size() != 0; } -template > +template +struct is_valid : std::false_type {}; + +template +struct is_valid(V)>())>> : std::bool_constant(V)>()> {}; + +template > +constexpr U ualue(std::size_t i) noexcept { + static_assert(is_enum_v, "nameof::detail::ualue requires enum type."); + + if constexpr (std::is_same_v) { // bool special case + static_assert(O == 0, "nameof::detail::ualue requires valid offset."); + + return static_cast(i); + } else if constexpr (IsFlags) { + return static_cast(U{1} << static_cast(static_cast(i) + O)); + } else { + return static_cast(static_cast(i) + O); + } +} + +template > constexpr E value(std::size_t i) noexcept { static_assert(is_enum_v, "nameof::detail::value requires enum type."); - if constexpr (std::is_same_v) { // bool special case - static_assert(O == 0, "nameof::detail::value requires valid offset."); - - return static_cast(i); - } else if constexpr (IsFlags) { - return static_cast(U{1} << static_cast(static_cast(i) + O)); - } else { - return static_cast(static_cast(i) + O); - } + return static_cast(ualue(i)); } template > @@ -638,7 +651,7 @@ constexpr std::size_t values_count(const bool (&valid)[N]) noexcept { template constexpr auto values(std::index_sequence) noexcept { static_assert(is_enum_v, "nameof::detail::values requires enum type."); - constexpr bool valid[sizeof...(I)] = {is_valid(I)>()...}; + constexpr bool valid[sizeof...(I)] = {is_valid(I)>::value...}; constexpr std::size_t count = values_count(valid); if constexpr (count > 0) {