Simplify umax

Add operator less and conversion operator.
This commit is contained in:
Nekotekina 2021-04-29 00:13:12 +03:00
parent b1736b6411
commit 5724d2d4c7
4 changed files with 11 additions and 27 deletions

View file

@ -480,39 +480,25 @@ struct get_int_impl<16>
};
// Return magic value for any unsigned type
constexpr inline struct umax_helper
constexpr struct umax_impl_t
{
constexpr umax_helper() noexcept = default;
template <typename T> requires (std::is_unsigned_v<std::common_type_t<T>>) || (std::is_same_v<std::common_type_t<T>, u128>)
friend constexpr bool operator==(const umax_helper&, const T& rhs)
constexpr bool operator==(const T& rhs) const
{
return rhs == static_cast<std::common_type_t<T>>(-1);
}
#if __cpp_impl_three_way_comparison >= 201711 && !__INTELLISENSE__
#else
template <typename T> requires (std::is_unsigned_v<std::common_type_t<T>>) || (std::is_same_v<std::common_type_t<T>, u128>)
friend constexpr bool operator==(const T& lhs, const umax_helper&)
constexpr bool operator<(const T& rhs) const
{
return lhs == static_cast<std::common_type_t<T>>(-1);
}
#endif
#if __cpp_impl_three_way_comparison >= 201711
#else
template <typename T> requires (std::is_unsigned_v<std::common_type_t<T>>) || (std::is_same_v<std::common_type_t<T>, u128>)
friend constexpr bool operator!=(const umax_helper&, const T& rhs)
{
return rhs != static_cast<std::common_type_t<T>>(-1);
return rhs < static_cast<std::common_type_t<T>>(-1);
}
template <typename T> requires (std::is_unsigned_v<std::common_type_t<T>>) || (std::is_same_v<std::common_type_t<T>, u128>)
friend constexpr bool operator!=(const T& lhs, const umax_helper&)
constexpr operator T() const
{
return lhs != static_cast<std::common_type_t<T>>(-1);
return static_cast<std::common_type_t<T>>(-1);
}
#endif
} umax;
enum class f16 : u16{};