From 57d7e795309437ec83246450b0b4f4bf60c5a82a Mon Sep 17 00:00:00 2001 From: neargye Date: Sun, 21 May 2023 17:38:39 +0400 Subject: [PATCH] clean-up --- include/magic_enum.hpp | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/include/magic_enum.hpp b/include/magic_enum.hpp index 10d4008..82eb42a 100644 --- a/include/magic_enum.hpp +++ b/include/magic_enum.hpp @@ -370,6 +370,15 @@ constexpr I log2(I value) noexcept { } } +#if defined(__cpp_lib_array_constexpr) && __cpp_lib_array_constexpr >= 201603L +#define MAGIC_ENUM_ARRAY_CONSTEXPR +#else +template +constexpr std::array, N> to_array(T (&a)[N], std::index_sequence) noexcept { + return {{a[I]...}}; +} +#endif + template inline constexpr bool is_enum_v = std::is_enum_v && std::is_same_v>; @@ -586,7 +595,6 @@ constexpr int reflected_max() noexcept { } } -#if defined(__cpp_lib_array_constexpr) && __cpp_lib_array_constexpr >= 201603L template constexpr std::size_t values_count(const bool (&valid)[N]) noexcept { auto count = std::size_t{0}; @@ -598,24 +606,6 @@ constexpr std::size_t values_count(const bool (&valid)[N]) noexcept { return count; } -#else -template -constexpr std::array, N> to_array(T (&a)[N], std::index_sequence) noexcept { - return {{a[I]...}}; -} - -template -constexpr std::size_t values_count(const bool (&valid)[N]) noexcept { - auto count = std::size_t{0}; - for (std::size_t i = 0; i < N; ++i) { - if (valid[i]) { - ++count; - } - } - - return count; -} -#endif template constexpr auto values(std::index_sequence) noexcept { @@ -624,9 +614,8 @@ constexpr auto values(std::index_sequence) noexcept { constexpr std::size_t count = values_count(valid); if constexpr (count > 0) { -#if defined(__cpp_lib_array_constexpr) && __cpp_lib_array_constexpr >= 201603L +#if defined(MAGIC_ENUM_ARRAY_CONSTEXPR) std::array values = {}; - #else E values[count] = {}; #endif @@ -635,7 +624,7 @@ constexpr auto values(std::index_sequence) noexcept { values[v++] = value(i); } } -#if defined(__cpp_lib_array_constexpr) && __cpp_lib_array_constexpr >= 201603L +#if defined(MAGIC_ENUM_ARRAY_CONSTEXPR) return values; #else return to_array(values, std::make_index_sequence{}); @@ -1602,4 +1591,10 @@ constexpr E& operator^=(E& lhs, E rhs) noexcept { # pragma warning(pop) #endif +#undef MAGIC_ENUM_GET_ENUM_NAME_BUILTIN +#undef MAGIC_ENUM_GET_TYPE_NAME_BUILTIN +#undef MAGIC_ENUM_ARRAY_CONSTEXPR +#undef MAGIC_ENUM_FOR_EACH_256 +#undef MAGIC_ENUM_CASE + #endif // NEARGYE_MAGIC_ENUM_HPP