From ef8fc89355bba8aa97abe9385e4023a0dcb2b318 Mon Sep 17 00:00:00 2001 From: Ivan Solovev Date: Tue, 1 Oct 2024 15:28:35 +0200 Subject: [PATCH] Move CompareThreeWayTester to qcomparehelpers.h We will need these checks in the qcomparehelpers.h header, so move the code there. As a drive-by, use QtOrderingPrivate namespace instead of QtPrivate, and also mark the constexpr bool variables as inline. This is required for the follow-up patches. Task-number: QTBUG-127095 Task-number: QTBUG-120305 Change-Id: I1ea827ecf68b6bffa347dae22ddac25c059b53a9 Reviewed-by: Marc Mutz (cherry picked from commit 678e9f614bc5a05d2ff16cf916397998e7cdfca1) --- src/corelib/global/qcompare.h | 47 ++++------------------------ src/corelib/global/qcomparehelpers.h | 36 +++++++++++++++++++++ 2 files changed, 42 insertions(+), 41 deletions(-) diff --git a/src/corelib/global/qcompare.h b/src/corelib/global/qcompare.h index fd9fb84c6b9..7fbf9aabcb3 100644 --- a/src/corelib/global/qcompare.h +++ b/src/corelib/global/qcompare.h @@ -629,42 +629,6 @@ QT_BEGIN_INCLUDE_NAMESPACE QT_END_INCLUDE_NAMESPACE -namespace QtPrivate { - -namespace CompareThreeWayTester { - - using Qt::compareThreeWay; - - // Check if compareThreeWay is implemented for the (LT, RT) argument - // pair. - template - constexpr bool hasCompareThreeWay = false; - - template - constexpr bool hasCompareThreeWay< - LT, RT, std::void_t(), std::declval()))> - > = true; - - // Check if the operation is noexcept. We have two different overloads, - // depending on the available compareThreeWay() implementation. - // Both are declared, but not implemented. To be used only in unevaluated - // context. - - template , bool> = true> - constexpr bool compareThreeWayNoexcept() noexcept - { return noexcept(compareThreeWay(std::declval(), std::declval())); } - - template && hasCompareThreeWay, - bool> = true> - constexpr bool compareThreeWayNoexcept() noexcept - { return noexcept(compareThreeWay(std::declval(), std::declval())); } - -} // namespace CompareThreeWayTester - -} // namespace QtPrivate - #if defined(Q_QDOC) template @@ -673,14 +637,15 @@ auto qCompareThreeWay(const LeftType &lhs, const RightType &rhs); #else template - || QtPrivate::CompareThreeWayTester::hasCompareThreeWay, - bool> = true> + std::enable_if_t< + QtOrderingPrivate::CompareThreeWayTester::hasCompareThreeWay + || QtOrderingPrivate::CompareThreeWayTester::hasCompareThreeWay, + bool> = true> auto qCompareThreeWay(const LT &lhs, const RT &rhs) - noexcept(QtPrivate::CompareThreeWayTester::compareThreeWayNoexcept()) + noexcept(QtOrderingPrivate::CompareThreeWayTester::compareThreeWayNoexcept()) { using Qt::compareThreeWay; - if constexpr (QtPrivate::CompareThreeWayTester::hasCompareThreeWay) { + if constexpr (QtOrderingPrivate::CompareThreeWayTester::hasCompareThreeWay) { return compareThreeWay(lhs, rhs); } else { const auto retval = compareThreeWay(rhs, lhs); diff --git a/src/corelib/global/qcomparehelpers.h b/src/corelib/global/qcomparehelpers.h index 8bf78d766bc..dcaa886bcdd 100644 --- a/src/corelib/global/qcomparehelpers.h +++ b/src/corelib/global/qcomparehelpers.h @@ -864,6 +864,42 @@ compareThreeWay(std::nullptr_t lhs, Qt::totally_ordered_wrapper rhs) noexcep template class QTypeInfo> : public QTypeInfo

{}; +namespace QtOrderingPrivate { + +namespace CompareThreeWayTester { + +using Qt::compareThreeWay; + +// Check if compareThreeWay is implemented for the (LT, RT) argument +// pair. +template +constexpr inline bool hasCompareThreeWay = false; + +template +constexpr inline bool hasCompareThreeWay< + LT, RT, std::void_t(), std::declval()))> + > = true; + +// Check if the operation is noexcept. We have two different overloads, +// depending on the available compareThreeWay() implementation. +// Both are declared, but not implemented. To be used only in unevaluated +// context. + +template , bool> = true> +constexpr bool compareThreeWayNoexcept() noexcept +{ return noexcept(compareThreeWay(std::declval(), std::declval())); } + +template && hasCompareThreeWay, + bool> = true> +constexpr bool compareThreeWayNoexcept() noexcept +{ return noexcept(compareThreeWay(std::declval(), std::declval())); } + +} // namespace CompareThreeWayTester + +} // namespace QtOrderingPrivate + QT_END_NAMESPACE namespace std {