From a6f4e55b4d80e8269d4419a66dd4ddc0ff60647f Mon Sep 17 00:00:00 2001 From: Ivan Solovev Date: Tue, 16 May 2023 18:08:22 +0200 Subject: [PATCH] QDate: use new comparison helper macros Comparison with std::chrono types is also supported due to implicit QDate constructors, which were made constexpr and noexcept in the previous patch. The unit-tests were already ported to the new comparison helper functions from QTestPrivate. Task-number: QTBUG-104111 Change-Id: Ib6b1122af9eaf2cb2c9db768150a31cf3bcadcc0 Reviewed-by: Edward Welbourne --- src/corelib/time/qdatetime.cpp | 12 ++++++------ src/corelib/time/qdatetime.h | 14 ++++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp index d1b07df07d..3651aaa9d7 100644 --- a/src/corelib/time/qdatetime.cpp +++ b/src/corelib/time/qdatetime.cpp @@ -1555,14 +1555,14 @@ qint64 QDate::daysTo(QDate d) const /*! - \fn bool QDate::operator==(QDate lhs, QDate rhs) + \fn bool QDate::operator==(const QDate &lhs, const QDate &rhs) Returns \c true if \a lhs and \a rhs represent the same day, otherwise \c false. */ /*! - \fn bool QDate::operator!=(QDate lhs, QDate rhs) + \fn bool QDate::operator!=(const QDate &lhs, const QDate &rhs) Returns \c true if \a lhs and \a rhs represent distinct days; otherwise returns \c false. @@ -1571,26 +1571,26 @@ qint64 QDate::daysTo(QDate d) const */ /*! - \fn bool QDate::operator<(QDate lhs, QDate rhs) + \fn bool QDate::operator<(const QDate &lhs, const QDate &rhs) Returns \c true if \a lhs is earlier than \a rhs; otherwise returns \c false. */ /*! - \fn bool QDate::operator<=(QDate lhs, QDate rhs) + \fn bool QDate::operator<=(const QDate &lhs, const QDate &rhs) Returns \c true if \a lhs is earlier than or equal to \a rhs; otherwise returns \c false. */ /*! - \fn bool QDate::operator>(QDate lhs, QDate rhs) + \fn bool QDate::operator>(const QDate &lhs, const QDate &rhs) Returns \c true if \a lhs is later than \a rhs; otherwise returns \c false. */ /*! - \fn bool QDate::operator>=(QDate lhs, QDate rhs) + \fn bool QDate::operator>=(const QDate &lhs, const QDate &rhs) Returns \c true if \a lhs is later than or equal to \a rhs; otherwise returns \c false. diff --git a/src/corelib/time/qdatetime.h b/src/corelib/time/qdatetime.h index bbfc0ec9fc..6183daa5a1 100644 --- a/src/corelib/time/qdatetime.h +++ b/src/corelib/time/qdatetime.h @@ -6,6 +6,7 @@ #define QDATETIME_H #include +#include #include #include #include @@ -170,12 +171,13 @@ private: friend class QDateTime; friend class QDateTimePrivate; - friend constexpr bool operator==(QDate lhs, QDate rhs) { return lhs.jd == rhs.jd; } - friend constexpr bool operator!=(QDate lhs, QDate rhs) { return lhs.jd != rhs.jd; } - friend constexpr bool operator< (QDate lhs, QDate rhs) { return lhs.jd < rhs.jd; } - friend constexpr bool operator<=(QDate lhs, QDate rhs) { return lhs.jd <= rhs.jd; } - friend constexpr bool operator> (QDate lhs, QDate rhs) { return lhs.jd > rhs.jd; } - friend constexpr bool operator>=(QDate lhs, QDate rhs) { return lhs.jd >= rhs.jd; } + friend constexpr bool comparesEqual(const QDate &lhs, const QDate &rhs) noexcept + { return lhs.jd == rhs.jd; } + friend constexpr Qt::strong_ordering + compareThreeWay(const QDate &lhs, const QDate &rhs) noexcept + { return Qt::compareThreeWay(lhs.jd, rhs.jd); } + Q_DECLARE_STRONGLY_ORDERED_LITERAL_TYPE(QDate) + #ifndef QT_NO_DATASTREAM friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, QDate); friend Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QDate &);