diff --git a/include/nameof.hpp b/include/nameof.hpp index 34e80db..4e5d690 100644 --- a/include/nameof.hpp +++ b/include/nameof.hpp @@ -153,9 +153,9 @@ class [[nodiscard]] cstring { ~cstring() = default; - constexpr cstring& operator=(const cstring&) = default; + cstring& operator=(const cstring&) = default; - constexpr cstring& operator=(cstring&&) = default; + cstring& operator=(cstring&&) = default; [[nodiscard]] constexpr const_pointer data() const noexcept { return chars_.data(); } @@ -408,6 +408,13 @@ constexpr auto n() noexcept { template inline constexpr auto enum_name_v = n(); +template +constexpr bool is_valid() noexcept { + static_assert(is_enum_v, "nameof::detail::is_valid requires enum type."); + + return n(V)>().size() != 0; +} + template constexpr bool cmp_less(L lhs, R rhs) noexcept { static_assert(std::is_integral_v && std::is_integral_v, "nameof::detail::cmp_less requires integral type."); @@ -463,7 +470,7 @@ inline constexpr int reflected_max_v = reflected_max(); template constexpr auto values(std::integer_sequence) noexcept { static_assert(is_enum_v, "nameof::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{}; @@ -483,10 +490,10 @@ template inline constexpr std::size_t count_v = values_v.size(); template -inline constexpr int min_v = values_v.empty() ? 0 : static_cast(values_v.front()); +inline constexpr int min_v = static_cast(values_v.front()); template -inline constexpr int max_v = values_v.empty() ? 0 : static_cast(values_v.back()); +inline constexpr int max_v = static_cast(values_v.back()); template inline constexpr std::size_t range_size_v = range_size, max_v>(); @@ -500,9 +507,9 @@ inline constexpr auto invalid_index_v = (std::numeric_limits>::max)() template constexpr auto indexes(std::integer_sequence) noexcept { static_assert(is_enum_v, "nameof::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