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 <marc.mutz@qt.io> (cherry picked from commit 678e9f614bc5a05d2ff16cf916397998e7cdfca1)
This commit is contained in:
parent
69da5314ff
commit
ef8fc89355
@ -629,42 +629,6 @@ QT_BEGIN_INCLUDE_NAMESPACE
|
|||||||
|
|
||||||
QT_END_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 <typename LT, typename RT, typename = void>
|
|
||||||
constexpr bool hasCompareThreeWay = false;
|
|
||||||
|
|
||||||
template <typename LT, typename RT>
|
|
||||||
constexpr bool hasCompareThreeWay<
|
|
||||||
LT, RT, std::void_t<decltype(compareThreeWay(std::declval<LT>(), std::declval<RT>()))>
|
|
||||||
> = 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 <typename LT, typename RT,
|
|
||||||
std::enable_if_t<hasCompareThreeWay<LT, RT>, bool> = true>
|
|
||||||
constexpr bool compareThreeWayNoexcept() noexcept
|
|
||||||
{ return noexcept(compareThreeWay(std::declval<LT>(), std::declval<RT>())); }
|
|
||||||
|
|
||||||
template <typename LT, typename RT,
|
|
||||||
std::enable_if_t<!hasCompareThreeWay<LT, RT> && hasCompareThreeWay<RT, LT>,
|
|
||||||
bool> = true>
|
|
||||||
constexpr bool compareThreeWayNoexcept() noexcept
|
|
||||||
{ return noexcept(compareThreeWay(std::declval<RT>(), std::declval<LT>())); }
|
|
||||||
|
|
||||||
} // namespace CompareThreeWayTester
|
|
||||||
|
|
||||||
} // namespace QtPrivate
|
|
||||||
|
|
||||||
#if defined(Q_QDOC)
|
#if defined(Q_QDOC)
|
||||||
|
|
||||||
template <typename LeftType, typename RightType>
|
template <typename LeftType, typename RightType>
|
||||||
@ -673,14 +637,15 @@ auto qCompareThreeWay(const LeftType &lhs, const RightType &rhs);
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
template <typename LT, typename RT,
|
template <typename LT, typename RT,
|
||||||
std::enable_if_t<QtPrivate::CompareThreeWayTester::hasCompareThreeWay<LT, RT>
|
std::enable_if_t<
|
||||||
|| QtPrivate::CompareThreeWayTester::hasCompareThreeWay<RT, LT>,
|
QtOrderingPrivate::CompareThreeWayTester::hasCompareThreeWay<LT, RT>
|
||||||
|
|| QtOrderingPrivate::CompareThreeWayTester::hasCompareThreeWay<RT, LT>,
|
||||||
bool> = true>
|
bool> = true>
|
||||||
auto qCompareThreeWay(const LT &lhs, const RT &rhs)
|
auto qCompareThreeWay(const LT &lhs, const RT &rhs)
|
||||||
noexcept(QtPrivate::CompareThreeWayTester::compareThreeWayNoexcept<LT, RT>())
|
noexcept(QtOrderingPrivate::CompareThreeWayTester::compareThreeWayNoexcept<LT, RT>())
|
||||||
{
|
{
|
||||||
using Qt::compareThreeWay;
|
using Qt::compareThreeWay;
|
||||||
if constexpr (QtPrivate::CompareThreeWayTester::hasCompareThreeWay<LT, RT>) {
|
if constexpr (QtOrderingPrivate::CompareThreeWayTester::hasCompareThreeWay<LT, RT>) {
|
||||||
return compareThreeWay(lhs, rhs);
|
return compareThreeWay(lhs, rhs);
|
||||||
} else {
|
} else {
|
||||||
const auto retval = compareThreeWay(rhs, lhs);
|
const auto retval = compareThreeWay(rhs, lhs);
|
||||||
|
@ -864,6 +864,42 @@ compareThreeWay(std::nullptr_t lhs, Qt::totally_ordered_wrapper<T*> rhs) noexcep
|
|||||||
template <typename P>
|
template <typename P>
|
||||||
class QTypeInfo<Qt::totally_ordered_wrapper<P>> : public QTypeInfo<P> {};
|
class QTypeInfo<Qt::totally_ordered_wrapper<P>> : public QTypeInfo<P> {};
|
||||||
|
|
||||||
|
namespace QtOrderingPrivate {
|
||||||
|
|
||||||
|
namespace CompareThreeWayTester {
|
||||||
|
|
||||||
|
using Qt::compareThreeWay;
|
||||||
|
|
||||||
|
// Check if compareThreeWay is implemented for the (LT, RT) argument
|
||||||
|
// pair.
|
||||||
|
template <typename LT, typename RT, typename = void>
|
||||||
|
constexpr inline bool hasCompareThreeWay = false;
|
||||||
|
|
||||||
|
template <typename LT, typename RT>
|
||||||
|
constexpr inline bool hasCompareThreeWay<
|
||||||
|
LT, RT, std::void_t<decltype(compareThreeWay(std::declval<LT>(), std::declval<RT>()))>
|
||||||
|
> = 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 <typename LT, typename RT,
|
||||||
|
std::enable_if_t<hasCompareThreeWay<LT, RT>, bool> = true>
|
||||||
|
constexpr bool compareThreeWayNoexcept() noexcept
|
||||||
|
{ return noexcept(compareThreeWay(std::declval<LT>(), std::declval<RT>())); }
|
||||||
|
|
||||||
|
template <typename LT, typename RT,
|
||||||
|
std::enable_if_t<!hasCompareThreeWay<LT, RT> && hasCompareThreeWay<RT, LT>,
|
||||||
|
bool> = true>
|
||||||
|
constexpr bool compareThreeWayNoexcept() noexcept
|
||||||
|
{ return noexcept(compareThreeWay(std::declval<RT>(), std::declval<LT>())); }
|
||||||
|
|
||||||
|
} // namespace CompareThreeWayTester
|
||||||
|
|
||||||
|
} // namespace QtOrderingPrivate
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user