Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Neargye authored and jamek committed Feb 11, 2022
1 parent 68933de commit ec9b31d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion include/magic_enum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,11 +404,23 @@ constexpr E value(std::size_t i) noexcept {
}
}

template <std::size_t N>
constexpr std::size_t values_count(const std::array<bool, N>& valid) noexcept {
auto count = std::size_t{0};
for (std::size_t i = 0; i < valid.size(); ++i) {
if (valid[i]) {
++count;
}
}

return count;
}

template <typename E, bool IsFlags, int Min, std::size_t... I>
constexpr auto values(std::index_sequence<I...>) noexcept {
static_assert(is_enum_v<E>, "magic_enum::detail::values requires enum type.");
constexpr std::array<bool, sizeof...(I)> valid{{is_valid<E, value<E, Min, IsFlags>(I)>()...}};
constexpr std::size_t count = (static_cast<std::size_t>(valid[I]) + ...);
constexpr std::size_t count = values_count(valid);

std::array<E, count> values{};
for (std::size_t i = 0, v = 0; v < count; ++i) {
Expand Down

0 comments on commit ec9b31d

Please sign in to comment.