From 091793ccaa5b11d91252a15e8452d6544e4e3504 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 28 Nov 2023 11:35:18 +0100 Subject: [PATCH] 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 --- src/corelib/global/qcomparehelpers.h | 32 +++++++------------ .../qcomparehelpers/tst_qcomparehelpers.cpp | 9 ++++-- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/corelib/global/qcomparehelpers.h b/src/corelib/global/qcomparehelpers.h index ad21d461b9f..d7e007b8b0a 100644 --- a/src/corelib/global/qcomparehelpers.h +++ b/src/corelib/global/qcomparehelpers.h @@ -353,23 +353,11 @@ constexpr bool IsFloatType_v = true; namespace Qt { -template -using if_integral = - std::enable_if_t> - && QtPrivate::IsIntegralType_v>, - bool>; +template +using if_integral = std::enable_if_t, bool>; -template -using if_floating_point = - std::enable_if_t> - && QtPrivate::IsFloatType_v>, - bool>; - -template -using if_integral_and_floating_point = - std::enable_if_t> - && QtPrivate::IsFloatType_v>, - bool>; +template +using if_floating_point = std::enable_if_t, bool>; template using if_compatible_pointers = @@ -382,7 +370,8 @@ template using if_enum = std::enable_if_t, bool>; template = true> + if_integral = true, + if_integral = true> constexpr Qt::strong_ordering compareThreeWay(LeftInt lhs, RightInt rhs) noexcept { static_assert(std::is_signed_v == std::is_signed_v, @@ -401,7 +390,8 @@ constexpr Qt::strong_ordering compareThreeWay(LeftInt lhs, RightInt rhs) noexcep } template = true> + if_floating_point = true, + if_floating_point = true> constexpr Qt::partial_ordering compareThreeWay(LeftFloat lhs, RightFloat rhs) noexcept { QT_WARNING_PUSH @@ -422,14 +412,16 @@ QT_WARNING_POP } template = true> + if_integral = true, + if_floating_point = true> constexpr Qt::partial_ordering compareThreeWay(IntType lhs, FloatType rhs) noexcept { return compareThreeWay(FloatType(lhs), rhs); } template = true> + if_floating_point = true, + if_integral = true> constexpr Qt::partial_ordering compareThreeWay(FloatType lhs, IntType rhs) noexcept { return compareThreeWay(lhs, FloatType(rhs)); diff --git a/tests/auto/corelib/global/qcomparehelpers/tst_qcomparehelpers.cpp b/tests/auto/corelib/global/qcomparehelpers/tst_qcomparehelpers.cpp index 86ca75680c9..c0911409d79 100644 --- a/tests/auto/corelib/global/qcomparehelpers/tst_qcomparehelpers.cpp +++ b/tests/auto/corelib/global/qcomparehelpers/tst_qcomparehelpers.cpp @@ -460,7 +460,8 @@ void tst_QCompareHelpers::generatedClasses() } template = true> + Qt::if_integral = true, + Qt::if_integral = true> void testOrderForTypes() { LeftType l0{0}; @@ -506,7 +507,8 @@ void testOrderForTypes() } template = true> + Qt::if_floating_point = true, + Qt::if_floating_point = true> void testOrderForTypes() { LeftType lNeg{-1.0}; @@ -575,7 +577,8 @@ void testOrderForTypes() } template = true> + Qt::if_integral = true, + Qt::if_floating_point = true> void testOrderForTypes() { IntType l0{0};