From 6206c6c189407f2d38fae921f3620a1c2a6f8d72 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Fri, 23 Oct 2020 14:43:09 +0200 Subject: [PATCH] Make QDate's operators hidden friends Adjust the documentation to match and add missing \c before false in two cases. Change-Id: Ic287c4de0b131c3500ee72bf1201900dc3788756 Reviewed-by: Volker Hilsheimer --- src/corelib/time/qdatetime.cpp | 26 ++++++++++++-------------- src/corelib/time/qdatetime.h | 14 +++++++------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp index 506430e154..eb9d5a82fd 100644 --- a/src/corelib/time/qdatetime.cpp +++ b/src/corelib/time/qdatetime.cpp @@ -1380,46 +1380,44 @@ qint64 QDate::daysTo(QDate d) const /*! - \fn bool QDate::operator==(QDate d) const + \fn bool QDate::operator==(QDate lhs, QDate rhs) - Returns \c true if this date and \a d represent the same day, otherwise + Returns \c true if \a lhs and \a rhs represent the same day, otherwise \c false. */ /*! - \fn bool QDate::operator!=(QDate d) const + \fn bool QDate::operator!=(QDate lhs, QDate rhs) - Returns \c true if this date is different from \a d; otherwise + Returns \c true if \a lhs and \a rhs represent distinct days; otherwise returns \c false. \sa operator==() */ /*! - \fn bool QDate::operator<(QDate d) const + \fn bool QDate::operator<(QDate lhs, QDate rhs) - Returns \c true if this date is earlier than \a d; otherwise returns - false. + Returns \c true if \a lhs is earlier than \a rhs; otherwise returns \c false. */ /*! - \fn bool QDate::operator<=(QDate d) const + \fn bool QDate::operator<=(QDate lhs, QDate rhs) - Returns \c true if this date is earlier than or equal to \a d; + Returns \c true if \a lhs is earlier than or equal to \a rhs; otherwise returns \c false. */ /*! - \fn bool QDate::operator>(QDate d) const + \fn bool QDate::operator>(QDate lhs, QDate rhs) - Returns \c true if this date is later than \a d; otherwise returns - false. + Returns \c true if \a lhs is later than \a rhs; otherwise returns \c false. */ /*! - \fn bool QDate::operator>=(QDate d) const + \fn bool QDate::operator>=(QDate lhs, QDate rhs) - Returns \c true if this date is later than or equal to \a d; + 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 fc43a1b302..e728a84385 100644 --- a/src/corelib/time/qdatetime.h +++ b/src/corelib/time/qdatetime.h @@ -117,13 +117,6 @@ public: [[nodiscard]] QDate addYears(int years, QCalendar cal) const; qint64 daysTo(QDate d) const; - constexpr bool operator==(QDate other) const { return jd == other.jd; } - constexpr bool operator!=(QDate other) const { return jd != other.jd; } - constexpr bool operator< (QDate other) const { return jd < other.jd; } - constexpr bool operator<=(QDate other) const { return jd <= other.jd; } - constexpr bool operator> (QDate other) const { return jd > other.jd; } - constexpr bool operator>=(QDate other) const { return jd >= other.jd; } - static QDate currentDate(); #if QT_CONFIG(datestring) static QDate fromString(QStringView string, Qt::DateFormat format = Qt::TextDate); @@ -155,6 +148,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; } #ifndef QT_NO_DATASTREAM friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, QDate); friend Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QDate &);