fix hard error if enum is empty or non-reflected

This commit is contained in:
neargye 2021-04-22 12:23:54 +03:00
parent b61944a3b6
commit d091ca081e

View file

@ -571,14 +571,18 @@ constexpr auto values(std::index_sequence<I...>) noexcept {
constexpr bool valid[sizeof...(I)] = {is_valid<E, value<E, Min, IsFlags>(I)>()...}; constexpr bool valid[sizeof...(I)] = {is_valid<E, value<E, Min, IsFlags>(I)>()...};
constexpr std::size_t count = values_count(valid); constexpr std::size_t count = values_count(valid);
E values[count] = {}; if constexpr (count > 0) {
for (std::size_t i = 0, v = 0; v < count; ++i) { E values[count] = {};
if (valid[i]) { for (std::size_t i = 0, v = 0; v < count; ++i) {
values[v++] = value<E, Min, IsFlags>(i); if (valid[i]) {
values[v++] = value<E, Min, IsFlags>(i);
}
} }
}
return to_array(values, std::make_index_sequence<count>{}); return to_array(values, std::make_index_sequence<count>{});
} else {
return std::array<E, 0>{};
}
} }
template <typename E, bool IsFlags, typename U = std::underlying_type_t<E>> template <typename E, bool IsFlags, typename U = std::underlying_type_t<E>>
@ -609,10 +613,10 @@ template <typename E, bool IsFlags = false>
inline constexpr auto count_v = values_v<E, IsFlags>.size(); inline constexpr auto count_v = values_v<E, IsFlags>.size();
template <typename E, bool IsFlags = false, typename U = std::underlying_type_t<E>> template <typename E, bool IsFlags = false, typename U = std::underlying_type_t<E>>
inline constexpr auto min_v = static_cast<U>(values_v<E, IsFlags>.front()); inline constexpr auto min_v = (count_v<E, IsFlags> > 0) ? static_cast<U>(values_v<E, IsFlags>.front()) : U{0};
template <typename E, bool IsFlags = false, typename U = std::underlying_type_t<E>> template <typename E, bool IsFlags = false, typename U = std::underlying_type_t<E>>
inline constexpr auto max_v = static_cast<U>(values_v<E, IsFlags>.back()); inline constexpr auto max_v = (count_v<E, IsFlags> > 0) ? static_cast<U>(values_v<E, IsFlags>.back()) : U{0};
template <typename E, bool IsFlags, typename U = std::underlying_type_t<E>> template <typename E, bool IsFlags, typename U = std::underlying_type_t<E>>
constexpr std::size_t range_size() noexcept { constexpr std::size_t range_size() noexcept {