1
0
Fork 0
mirror of https://github.com/Neargye/magic_enum.git synced 2026-01-09 23:34:23 +00:00

Sparse only if have an element. Switch only if -. (#169)

This commit is contained in:
Bela Schaum 2022-03-18 10:59:09 +01:00 committed by GitHub
parent 60de6bff8c
commit 492d2b6a18
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -601,7 +601,7 @@ constexpr bool is_sparse() noexcept {
constexpr auto min = is_flags_v<E> ? log2(min_v<E>) : min_v<E>;
constexpr auto range_size = max - min + 1;
return range_size != count_v<E>;
return range_size != count_v<E> && count_v<E> > 0;
}
template <typename E>
@ -1092,7 +1092,7 @@ template <typename E, typename BinaryPredicate = std::equal_to<char>>
return static_cast<D>(result);
}
return {}; // Invalid value or out of range.
} else {
} else if constexpr (detail::count_v<D> > 0) {
constexpr bool default_predicate =
std::is_same_v<std::decay_t<BinaryPredicate>, std::equal_to<char>> ||
std::is_same_v<std::decay_t<BinaryPredicate>, std::equal_to<>>;
@ -1110,6 +1110,8 @@ template <typename E, typename BinaryPredicate = std::equal_to<char>>
}
return {}; // Invalid value or out of range.
}
} else {
return {};
}
}