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

fix enums with underlying type bool

This commit is contained in:
neargye 2021-06-24 11:47:06 +03:00
parent 5003c436d6
commit 739942ab7d
2 changed files with 18 additions and 2 deletions

View file

@ -383,7 +383,9 @@ constexpr int reflected_min() noexcept {
static_assert(lhs > (std::numeric_limits<std::int16_t>::min)(), "magic_enum::enum_range requires min must be greater than INT16_MIN.");
constexpr auto rhs = (std::numeric_limits<U>::min)();
if constexpr (cmp_less(lhs, rhs)) {
if constexpr (std::is_same_v<bool, U>) {
return static_cast<int>(rhs);
} else if constexpr (cmp_less(lhs, rhs)) {
return rhs;
} else {
static_assert(!is_valid<E, value<E, lhs - 1, IsFlags>(0)>(), "magic_enum::enum_range detects enum value smaller than min range size.");
@ -403,7 +405,9 @@ constexpr int reflected_max() noexcept {
static_assert(lhs < (std::numeric_limits<std::int16_t>::max)(), "magic_enum::enum_range requires max must be less than INT16_MAX.");
constexpr auto rhs = (std::numeric_limits<U>::max)();
if constexpr (cmp_less(lhs, rhs)) {
if constexpr (std::is_same_v<bool, U>) {
return static_cast<int>(rhs);
} else if constexpr (cmp_less(lhs, rhs)) {
static_assert(!is_valid<E, value<E, lhs + 1, IsFlags>(0)>(), "magic_enum::enum_range detects enum value larger than max range size.");
return lhs;
} else {