From 3a8a8b42909f13a3130d9154363fa0e83cdc0957 Mon Sep 17 00:00:00 2001 From: Ivan Solovev Date: Wed, 4 Dec 2024 13:17:51 +0100 Subject: [PATCH] DRY QList and QVLA operator<=>() implementation Both QList and QVLA defined an if_has_op_less_or_op_compare_three_way trait. The only difference was that QList's implementation was using QTypeTraits::has_operator_less_than_container<>, and thus required a Container template parameter, while QVLA didn't need it. However, QVLA would still work properly with the _container version of the trait, so move the QList's implementation into QtOrderingPrivate and use it consistently in both classes. Task-number: QTBUG-120305 Change-Id: I1e4415ae5a25d4faad218bbad979a49ce851d557 Reviewed-by: Marc Mutz --- src/corelib/global/qcomparehelpers.h | 7 +++++++ src/corelib/tools/qlist.h | 10 ++-------- src/corelib/tools/qvarlengtharray.h | 9 +-------- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/corelib/global/qcomparehelpers.h b/src/corelib/global/qcomparehelpers.h index 8ce91229b7f..ede96a83cf6 100644 --- a/src/corelib/global/qcomparehelpers.h +++ b/src/corelib/global/qcomparehelpers.h @@ -1250,6 +1250,13 @@ constexpr bool compareThreeWayNoexcept() noexcept } } } synthThreeWay; + +template +using if_has_op_less_or_op_compare_three_way = + std::enable_if_t< + std::disjunction_v, + QTypeTraits::has_operator_compare_three_way>, + bool>; #endif // __cpp_lib_three_way_comparison // These checks do not use Qt::compareThreeWay(), so only work for user-defined diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 8ccf512389d..45ecac01574 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -349,14 +349,8 @@ private: } #if defined(__cpp_lib_three_way_comparison) && defined(__cpp_lib_concepts) - template - using if_has_op_less_or_op_compare_three_way = - std::enable_if_t< - std::disjunction_v, - QTypeTraits::has_operator_compare_three_way>, - bool>; - - template = true> + template = true> friend auto operator<=>(const QList &lhs, const QList &rhs) { return std::lexicographical_compare_three_way(lhs.begin(), lhs.end(), diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index fb3c53c49cd..cb148075e3f 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -640,15 +640,8 @@ private: } #if defined(__cpp_lib_three_way_comparison) && defined(__cpp_lib_concepts) - template - using if_has_op_less_or_op_compare_three_way = - std::enable_if_t< - std::disjunction_v, - QTypeTraits::has_operator_compare_three_way>, - bool>; - template = true> + QtOrderingPrivate::if_has_op_less_or_op_compare_three_way = true> friend auto operator<=>(const QVarLengthArray &lhs, const QVarLengthArray &rhs) {