diff --git a/include/magic_enum.hpp b/include/magic_enum.hpp index 0b6dda9..e475a7d 100644 --- a/include/magic_enum.hpp +++ b/include/magic_enum.hpp @@ -169,7 +169,7 @@ class static_string { assert(str.size() == N); } - constexpr const char* data() const noexcept { return chars_.data(); } + constexpr const char* data() const noexcept { return chars_; } constexpr std::size_t size() const noexcept { return N; } @@ -177,9 +177,9 @@ class static_string { private: template - constexpr static_string(string_view str, std::index_sequence) noexcept : chars_{{str[I]..., '\0'}} {} + constexpr static_string(string_view str, std::index_sequence) noexcept : chars_{str[I]..., '\0'} {} - const std::array chars_; + char chars_[N + 1]; }; template <> @@ -235,6 +235,11 @@ constexpr std::size_t find(string_view str, char c) noexcept { } } +template +constexpr std::array, N> to_array(T (&a)[N], std::index_sequence) { + return {{a[I]...}}; +} + template constexpr bool cmp_equal(string_view lhs, string_view rhs, BinaryPredicate&& p) noexcept(std::is_nothrow_invocable_r_v) { #if defined(_MSC_VER) && _MSC_VER < 1920 && !defined(__clang__) @@ -409,9 +414,9 @@ constexpr E value(std::size_t i) noexcept { } template -constexpr std::size_t values_count(const std::array& valid) noexcept { +constexpr std::size_t values_count(const bool (&valid)[N]) noexcept { auto count = std::size_t{0}; - for (std::size_t i = 0; i < valid.size(); ++i) { + for (std::size_t i = 0; i < N; ++i) { if (valid[i]) { ++count; } @@ -423,17 +428,17 @@ constexpr std::size_t values_count(const std::array& valid) noexcept { template constexpr auto values(std::index_sequence) noexcept { static_assert(is_enum_v, "magic_enum::detail::values requires enum type."); - constexpr std::array valid{{is_valid(I)>()...}}; + constexpr bool valid[sizeof...(I)] = {is_valid(I)>()...}; constexpr std::size_t count = values_count(valid); - std::array values{}; + E values[count] = {}; for (std::size_t i = 0, v = 0; v < count; ++i) { if (valid[i]) { values[v++] = value(i); } } - return values; + return to_array(values, std::make_index_sequence{}); } template >