diff --git a/Utilities/types.h b/Utilities/types.h index d076db6df1..f6d3a0a876 100644 --- a/Utilities/types.h +++ b/Utilities/types.h @@ -409,6 +409,48 @@ struct alignas(16) s128 CHECK_SIZE_ALIGN(u128, 16, 16); CHECK_SIZE_ALIGN(s128, 16, 16); +// Return magic value for any unsigned type +constexpr inline struct umax_helper +{ + constexpr umax_helper() noexcept = default; + + template >, typename = std::enable_if_t>> + explicit constexpr operator T() const + { + return std::numeric_limits::max(); + } + + template >, typename = std::enable_if_t>> + constexpr bool operator==(const T& rhs) const + { + return rhs == std::numeric_limits>>::max(); + } + +#if __cpp_impl_three_way_comparison >= 201711 && !__INTELLISENSE__ +#else + template + friend constexpr std::enable_if_t>>, bool> operator==(const T& lhs, const umax_helper& rhs) + { + return rhs == lhs; + } +#endif + +#if __cpp_impl_three_way_comparison >= 201711 +#else + template >, typename = std::enable_if_t>> + constexpr bool operator!=(const T& rhs) const + { + return rhs != std::numeric_limits>>::max(); + } + + template + friend constexpr std::enable_if_t>>, bool> operator!=(const T& lhs, const umax_helper& rhs) + { + return rhs != lhs; + } +#endif +} umax; + using f32 = float; using f64 = double;