qcomparehelper.h: simplify compareThreeWay() SFINAE helpers

There's no restriction on the number of enable_if's in a
template-initializer, so simplify the compareThreeWay() constraints by
having separate constraints each for LeftType and RightType. Fewer
templates to instantiate = faster compile speed.

As a drive-by, drop remove_reference_t. We control all users and all of
them pass already-decayed types.

Change-Id: I17c01c7aa1ac03bb6db4b0bef1371ebc0641641d
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
This commit is contained in:
Marc Mutz 2023-11-28 11:35:18 +01:00 committed by Ivan Solovev
parent 4b755bc11a
commit 091793ccaa
2 changed files with 18 additions and 23 deletions

View File

@ -353,23 +353,11 @@ constexpr bool IsFloatType_v<QtPrivate::NativeFloat16Type> = true;
namespace Qt {
template <typename T, typename U>
using if_integral =
std::enable_if_t<QtPrivate::IsIntegralType_v<std::remove_reference_t<T>>
&& QtPrivate::IsIntegralType_v<std::remove_reference_t<U>>,
bool>;
template <typename T>
using if_integral = std::enable_if_t<QtPrivate::IsIntegralType_v<T>, bool>;
template <typename T, typename U>
using if_floating_point =
std::enable_if_t<QtPrivate::IsFloatType_v<std::remove_reference_t<T>>
&& QtPrivate::IsFloatType_v<std::remove_reference_t<U>>,
bool>;
template <typename T, typename U>
using if_integral_and_floating_point =
std::enable_if_t<QtPrivate::IsIntegralType_v<std::remove_reference_t<T>>
&& QtPrivate::IsFloatType_v<std::remove_reference_t<U>>,
bool>;
template <typename T>
using if_floating_point = std::enable_if_t<QtPrivate::IsFloatType_v<T>, bool>;
template <typename T, typename U>
using if_compatible_pointers =
@ -382,7 +370,8 @@ template <typename Enum>
using if_enum = std::enable_if_t<std::is_enum_v<Enum>, bool>;
template <typename LeftInt, typename RightInt,
if_integral<LeftInt, RightInt> = true>
if_integral<LeftInt> = true,
if_integral<RightInt> = true>
constexpr Qt::strong_ordering compareThreeWay(LeftInt lhs, RightInt rhs) noexcept
{
static_assert(std::is_signed_v<LeftInt> == std::is_signed_v<RightInt>,
@ -401,7 +390,8 @@ constexpr Qt::strong_ordering compareThreeWay(LeftInt lhs, RightInt rhs) noexcep
}
template <typename LeftFloat, typename RightFloat,
if_floating_point<LeftFloat, RightFloat> = true>
if_floating_point<LeftFloat> = true,
if_floating_point<RightFloat> = true>
constexpr Qt::partial_ordering compareThreeWay(LeftFloat lhs, RightFloat rhs) noexcept
{
QT_WARNING_PUSH
@ -422,14 +412,16 @@ QT_WARNING_POP
}
template <typename IntType, typename FloatType,
if_integral_and_floating_point<IntType, FloatType> = true>
if_integral<IntType> = true,
if_floating_point<FloatType> = true>
constexpr Qt::partial_ordering compareThreeWay(IntType lhs, FloatType rhs) noexcept
{
return compareThreeWay(FloatType(lhs), rhs);
}
template <typename FloatType, typename IntType,
if_integral_and_floating_point<IntType, FloatType> = true>
if_floating_point<FloatType> = true,
if_integral<IntType> = true>
constexpr Qt::partial_ordering compareThreeWay(FloatType lhs, IntType rhs) noexcept
{
return compareThreeWay(lhs, FloatType(rhs));

View File

@ -460,7 +460,8 @@ void tst_QCompareHelpers::generatedClasses()
}
template <typename LeftType, typename RightType,
Qt::if_integral<LeftType, RightType> = true>
Qt::if_integral<LeftType> = true,
Qt::if_integral<RightType> = true>
void testOrderForTypes()
{
LeftType l0{0};
@ -506,7 +507,8 @@ void testOrderForTypes()
}
template <typename LeftType, typename RightType,
Qt::if_floating_point<LeftType, RightType> = true>
Qt::if_floating_point<LeftType> = true,
Qt::if_floating_point<RightType> = true>
void testOrderForTypes()
{
LeftType lNeg{-1.0};
@ -575,7 +577,8 @@ void testOrderForTypes()
}
template <typename IntType, typename FloatType,
Qt::if_integral_and_floating_point<IntType, FloatType> = true>
Qt::if_integral<IntType> = true,
Qt::if_floating_point<FloatType> = true>
void testOrderForTypes()
{
IntType l0{0};