diff --git a/include/nameof.hpp b/include/nameof.hpp index 223bb03..c847b2b 100644 --- a/include/nameof.hpp +++ b/include/nameof.hpp @@ -63,6 +63,16 @@ struct enum_range final { static_assert(max > min, "nameof::enum_range requires max > min."); }; +static_assert(NAMEOF_ENUM_RANGE_MIN <= 0, + "NAMEOF_ENUM_RANGE_MIN must be less or equals than 0."); +static_assert(NAMEOF_ENUM_RANGE_MIN > (std::numeric_limits::min)(), + "NAMEOF_ENUM_RANGE_MIN must be greater than INT_MIN."); + +static_assert(NAMEOF_ENUM_RANGE_MAX > 0, + "NAMEOF_ENUM_RANGE_MAX must be greater than 0."); +static_assert(NAMEOF_ENUM_RANGE_MAX < (std::numeric_limits::max)(), + "NAMEOF_ENUM_RANGE_MAX must be less than INT_MAX."); + namespace detail { template @@ -219,8 +229,8 @@ template constexpr auto range = std::make_integer_sequence{}; constexpr auto names = detail::enum_names_impl(range); - if (int i = static_cast(value) - min; i >= 0 && static_cast(i) < names.size()) { - return names[static_cast(i)]; + if (auto i = static_cast(static_cast(value) - min); i < names.size()) { + return names[i]; } else { return {}; // Value out of range. }