From f4738bef44782f161e949a831cb18910a9b2a5ba Mon Sep 17 00:00:00 2001 From: neargye Date: Fri, 26 Nov 2021 11:11:51 +0200 Subject: [PATCH] fix hard-limit on enum range --- include/magic_enum.hpp | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/include/magic_enum.hpp b/include/magic_enum.hpp index f122000..5cc6617 100644 --- a/include/magic_enum.hpp +++ b/include/magic_enum.hpp @@ -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::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::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::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 @@ -392,7 +387,6 @@ constexpr int reflected_min() noexcept { return 0; } else { constexpr auto lhs = customize::enum_range::min; - static_assert(lhs > (std::numeric_limits::min)(), "magic_enum::enum_range requires min must be greater than INT16_MIN."); constexpr auto rhs = (std::numeric_limits::min)(); if constexpr (cmp_less(rhs, lhs)) { @@ -412,7 +406,6 @@ constexpr int reflected_max() noexcept { return std::numeric_limits::digits - 1; } else { constexpr auto lhs = customize::enum_range::max; - static_assert(lhs < (std::numeric_limits::max)(), "magic_enum::enum_range requires max must be less than INT16_MAX."); constexpr auto rhs = (std::numeric_limits::max)(); if constexpr (cmp_less(lhs, rhs)) { @@ -494,7 +487,7 @@ constexpr std::size_t range_size() noexcept { static_assert(is_enum_v, "magic_enum::detail::range_size requires enum type."); constexpr auto max = IsFlags ? log2(max_v) : max_v; constexpr auto min = IsFlags ? log2(min_v) : min_v; - 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::max)(), "magic_enum::enum_range requires valid size.");