From bcbabba3e4cdda76107dc4a3e789f1e5c0c785aa Mon Sep 17 00:00:00 2001 From: neargye Date: Wed, 8 Jul 2020 21:14:43 +0500 Subject: [PATCH] wip --- include/magic_enum.hpp | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/include/magic_enum.hpp b/include/magic_enum.hpp index d20520e..6fb6d12 100644 --- a/include/magic_enum.hpp +++ b/include/magic_enum.hpp @@ -105,18 +105,6 @@ struct supported : std::false_type {}; #endif -template -struct has_min : std::false_type {}; - -template -struct has_min::min)>> : std::true_type {}; - -template -struct has_max : std::false_type {}; - -template -struct has_max::max)>> : std::true_type {}; - template inline constexpr bool is_enum_v = std::is_enum_v && std::is_same_v>; @@ -286,7 +274,6 @@ constexpr int reflected_min() noexcept { if constexpr (IsFlags) { return 0; } else { - static_assert(has_min::value, "magic_enum::enum_range requires min."); constexpr auto lhs = 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)(); @@ -306,7 +293,6 @@ constexpr int reflected_max() noexcept { if constexpr (IsFlags) { return (std::numeric_limits::max)(); } else { - static_assert(has_max::value, "magic_enum::enum_range requires max."); constexpr auto lhs = 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)(); @@ -744,8 +730,8 @@ namespace ostream_operators { template , int> = 0> auto& operator<<(std::basic_ostream& os, E value) { -#if defined(MAGIC_ENUM_SUPPORTED) && MAGIC_ENUM_SUPPORTED using D = std::decay_t; +#if defined(MAGIC_ENUM_SUPPORTED) && MAGIC_ENUM_SUPPORTED using namespace magic_enum; if (const auto name = enum_name(value); !name.empty()) { @@ -756,7 +742,7 @@ auto& operator<<(std::basic_ostream& os, E value) { os << enum_integer(value); } #else - os << static_cast>(value); + os << static_cast(value); #endif return os; } @@ -885,14 +871,9 @@ template template [[nodiscard]] constexpr auto enum_contains(underlying_type_t value) noexcept -> detail::enable_if_enum_flags_t { using D = std::decay_t; - using U = std::underlying_type_t; if constexpr (detail::is_sparse_v) { - constexpr auto min = detail::min_v; - constexpr auto max = detail::value_ors(); - - return value >= min && value <= max; - } else { + using U = std::underlying_type_t; auto check_value = U{0}; for (std::size_t i = 0; i < detail::count_v; ++i) { if (const auto v = static_cast(enum_value(i)); (static_cast(value) & v) != 0) { @@ -901,6 +882,11 @@ template } return check_value == value; + } else { + constexpr auto min = detail::min_v; + constexpr auto max = detail::value_ors(); + + return value >= min && value <= max; } }