add more assert

This commit is contained in:
terik23 2019-07-14 21:00:34 +05:00
parent 241c6d9906
commit 07e7d8dff6

View file

@ -73,6 +73,9 @@ static_assert(NAMEOF_ENUM_RANGE_MAX > 0,
static_assert(NAMEOF_ENUM_RANGE_MAX < (std::numeric_limits<int>::max)(), static_assert(NAMEOF_ENUM_RANGE_MAX < (std::numeric_limits<int>::max)(),
"NAMEOF_ENUM_RANGE_MAX must be less than INT_MAX."); "NAMEOF_ENUM_RANGE_MAX must be less than INT_MAX.");
static_assert(NAMEOF_ENUM_RANGE_MAX > NAMEOF_ENUM_RANGE_MIN,
"NAMEOF_ENUM_RANGE_MAX must be greater than NAMEOF_ENUM_RANGE_MIN.");
namespace detail { namespace detail {
template <typename T> template <typename T>
@ -222,6 +225,8 @@ template <typename E>
[[nodiscard]] constexpr std::enable_if_t<std::is_enum_v<std::decay_t<E>>, std::string_view> nameof_enum(E value) noexcept { [[nodiscard]] constexpr std::enable_if_t<std::is_enum_v<std::decay_t<E>>, std::string_view> nameof_enum(E value) noexcept {
using D = std::decay_t<E>; using D = std::decay_t<E>;
static_assert(std::is_enum_v<D>, "nameof::nameof_enum requires enum type."); static_assert(std::is_enum_v<D>, "nameof::nameof_enum requires enum type.");
static_assert(enum_range<D>::min > (std::numeric_limits<int>::min)(), "nameof::enum_range requires min must be greater than INT_MIN.");
static_assert(enum_range<D>::max < (std::numeric_limits<int>::max)(), "nameof::enum_range requires max must be less than INT_MAX.");
static_assert(enum_range<D>::max > enum_range<D>::min, "nameof::enum_range requires max > min."); static_assert(enum_range<D>::max > enum_range<D>::min, "nameof::enum_range requires max > min.");
using U = std::underlying_type_t<D>; using U = std::underlying_type_t<D>;
constexpr int max = enum_range<D>::max < (std::numeric_limits<U>::max)() ? enum_range<D>::max : (std::numeric_limits<U>::max)(); constexpr int max = enum_range<D>::max < (std::numeric_limits<U>::max)() ? enum_range<D>::max : (std::numeric_limits<U>::max)();