mirror of
https://github.com/Neargye/magic_enum.git
synced 2026-01-10 23:44:29 +00:00
fix hard-limit on enum range
This commit is contained in:
parent
5bc2689fa5
commit
f4738bef44
1 changed files with 2 additions and 9 deletions
|
|
@ -131,13 +131,8 @@ struct enum_range {
|
|||
static_assert(max > min, "magic_enum::customize::enum_range requires max > min.");
|
||||
};
|
||||
|
||||
static_assert(MAGIC_ENUM_RANGE_MIN <= 0, "MAGIC_ENUM_RANGE_MIN must be less or equals than 0.");
|
||||
static_assert(MAGIC_ENUM_RANGE_MIN > (std::numeric_limits<std::int16_t>::min)(), "MAGIC_ENUM_RANGE_MIN must be greater than INT16_MIN.");
|
||||
|
||||
static_assert(MAGIC_ENUM_RANGE_MAX > 0, "MAGIC_ENUM_RANGE_MAX must be greater than 0.");
|
||||
static_assert(MAGIC_ENUM_RANGE_MAX < (std::numeric_limits<std::int16_t>::max)(), "MAGIC_ENUM_RANGE_MAX must be less than INT16_MAX.");
|
||||
|
||||
static_assert(MAGIC_ENUM_RANGE_MAX > MAGIC_ENUM_RANGE_MIN, "MAGIC_ENUM_RANGE_MAX must be greater than MAGIC_ENUM_RANGE_MIN.");
|
||||
static_assert((MAGIC_ENUM_RANGE_MAX - MAGIC_ENUM_RANGE_MIN) < (std::numeric_limits<std::uint16_t>::max)(), "MAGIC_ENUM_RANGE must be less than UINT16_MAX.");
|
||||
|
||||
// If need custom names for enum, add specialization enum_name for necessary enum type.
|
||||
template <typename E>
|
||||
|
|
@ -392,7 +387,6 @@ constexpr int reflected_min() noexcept {
|
|||
return 0;
|
||||
} else {
|
||||
constexpr auto lhs = customize::enum_range<E>::min;
|
||||
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(rhs, lhs)) {
|
||||
|
|
@ -412,7 +406,6 @@ constexpr int reflected_max() noexcept {
|
|||
return std::numeric_limits<U>::digits - 1;
|
||||
} else {
|
||||
constexpr auto lhs = customize::enum_range<E>::max;
|
||||
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)) {
|
||||
|
|
@ -494,7 +487,7 @@ constexpr std::size_t range_size() noexcept {
|
|||
static_assert(is_enum_v<E>, "magic_enum::detail::range_size requires enum type.");
|
||||
constexpr auto max = IsFlags ? log2(max_v<E, IsFlags>) : max_v<E, IsFlags>;
|
||||
constexpr auto min = IsFlags ? log2(min_v<E, IsFlags>) : min_v<E, IsFlags>;
|
||||
constexpr auto range_size = max - min + U{1};
|
||||
constexpr auto range_size = max - min + 1;
|
||||
static_assert(range_size > 0, "magic_enum::enum_range requires valid size.");
|
||||
static_assert(range_size < (std::numeric_limits<std::uint16_t>::max)(), "magic_enum::enum_range requires valid size.");
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue