Another attempt on umax

This commit is contained in:
Nekotekina 2020-02-20 15:00:22 +03:00
parent 987223da3f
commit 2f255a528e

View file

@ -414,39 +414,39 @@ constexpr inline struct umax_helper
{ {
constexpr umax_helper() noexcept = default; constexpr umax_helper() noexcept = default;
template <typename T, typename S = simple_t<std::decay_t<T>>, typename = std::enable_if_t<std::is_unsigned_v<S>>> template <typename T, typename S = simple_t<T>, typename = std::enable_if_t<std::is_unsigned_v<S>>>
explicit constexpr operator T() const explicit constexpr operator T() const
{ {
return std::numeric_limits<S>::max(); return std::numeric_limits<S>::max();
} }
template <typename T, typename S = simple_t<std::decay_t<T>>, typename = std::enable_if_t<std::is_unsigned_v<S>>> template <typename T, typename S = simple_t<T>, typename = std::enable_if_t<std::is_unsigned_v<S>>>
constexpr bool operator==(const T& rhs) const constexpr bool operator==(const T& rhs) const
{ {
return rhs == std::numeric_limits<simple_t<std::decay_t<T>>>::max(); return std::numeric_limits<S>::max() == rhs;
} }
#if __cpp_impl_three_way_comparison >= 201711 && !__INTELLISENSE__ #if __cpp_impl_three_way_comparison >= 201711 && !__INTELLISENSE__
#else #else
template <typename T> template <typename T>
friend constexpr std::enable_if_t<std::is_unsigned_v<simple_t<std::decay_t<T>>>, bool> operator==(const T& lhs, const umax_helper& rhs) friend constexpr std::enable_if_t<std::is_unsigned_v<simple_t<T>>, bool> operator==(const T& lhs, const umax_helper& rhs)
{ {
return rhs == lhs; return std::numeric_limits<simple_t<T>>::max() == lhs;
} }
#endif #endif
#if __cpp_impl_three_way_comparison >= 201711 #if __cpp_impl_three_way_comparison >= 201711
#else #else
template <typename T, typename S = simple_t<std::decay_t<T>>, typename = std::enable_if_t<std::is_unsigned_v<S>>> template <typename T, typename S = simple_t<T>, typename = std::enable_if_t<std::is_unsigned_v<S>>>
constexpr bool operator!=(const T& rhs) const constexpr bool operator!=(const T& rhs) const
{ {
return rhs != std::numeric_limits<simple_t<std::decay_t<T>>>::max(); return std::numeric_limits<S>::max() != rhs;
} }
template <typename T> template <typename T>
friend constexpr std::enable_if_t<std::is_unsigned_v<simple_t<std::decay_t<T>>>, bool> operator!=(const T& lhs, const umax_helper& rhs) friend constexpr std::enable_if_t<std::is_unsigned_v<simple_t<T>>, bool> operator!=(const T& lhs, const umax_helper& rhs)
{ {
return rhs != lhs; return std::numeric_limits<simple_t<T>>::max() != lhs;
} }
#endif #endif
} umax; } umax;