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,6 +571,7 @@ constexpr auto values(std::index_sequence<I...>) noexcept {
constexpr bool valid[sizeof...(I)] = {is_valid<E, value<E, Min, IsFlags>(I)>()...};
constexpr std::size_t count = values_count(valid);
if constexpr (count > 0) {
E values[count] = {};
for (std::size_t i = 0, v = 0; v < count; ++i) {
if (valid[i]) {
@ -579,6 +580,9 @@ constexpr auto values(std::index_sequence<I...>) noexcept {
}
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>>
@ -609,10 +613,10 @@ template <typename E, bool IsFlags = false>
inline constexpr auto count_v = values_v<E, IsFlags>.size();
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>>
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>>
constexpr std::size_t range_size() noexcept {