diff options
author | Tatiana Borisova <tatiana.borisova@qt.io> | 2024-03-11 19:39:08 +0100 |
---|---|---|
committer | Tatiana Borisova <tatiana.borisova@qt.io> | 2024-03-19 14:38:11 +0000 |
commit | 8ed8844343652e70a40d9d6d254296f139120427 (patch) | |
tree | afd942537192aeb8fb548bde6c27ee9d57c2e84a /src/corelib/serialization/qcborarray.h | |
parent | 5e81a17b224b8cda03704b045b437ba11726a744 (diff) |
QCborArray: use new comparison helper macros
Replace public operators operator==(), operator!=(), operator<() of
QCborArray to friend methods comparesEqual() / compareThreeWay().
Use QT_CORE_REMOVED_SINCE to get rid of current comparison methods
and replace them with a friend.
Delete #if 0 && __has_include(<compare>) blocks,
since they are not required anymore.
Add friend methods comparesEqual(QCborArray, QCborValueConstRef)
and compareThreeWay(QCborArray, QCborValueConstRef) to QCborArray
to support comparison between QCborArray and
QCborValueRef/QCborValueConstRef, see test-case mapMutation().
Add QT_TEST_EQUALITY_OPS/QT_TEST_ALL_COMPARISON_OPS tests for QCborArray
test-cases.
Task-number: QTBUG-120300
Change-Id: Ifad1a04c61363618e8bba73cf7c87757552d722a
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/serialization/qcborarray.h')
-rw-r--r-- | src/corelib/serialization/qcborarray.h | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/src/corelib/serialization/qcborarray.h b/src/corelib/serialization/qcborarray.h index 2ac778ce47..777321a747 100644 --- a/src/corelib/serialization/qcborarray.h +++ b/src/corelib/serialization/qcborarray.h @@ -181,19 +181,11 @@ public: bool contains(const QCborValue &value) const; int compare(const QCborArray &other) const noexcept Q_DECL_PURE_FUNCTION; -#if 0 && __has_include(<compare>) - std::strong_ordering operator<=>(const QCborArray &other) const - { - int c = compare(other); - if (c > 0) return std::strong_ordering::greater; - if (c == 0) return std::strong_ordering::equivalent; - return std::strong_ordering::less; - } -#else +#if QT_CORE_REMOVED_SINCE(6, 8) bool operator==(const QCborArray &other) const noexcept { return compare(other) == 0; } bool operator!=(const QCborArray &other) const noexcept - { return !(*this == other); } + { return !operator==(other); } bool operator<(const QCborArray &other) const { return compare(other) < 0; } #endif @@ -237,6 +229,31 @@ public: QJsonArray toJsonArray() const; private: + friend bool comparesEqual(const QCborArray &lhs, const QCborArray &rhs) noexcept + { + return lhs.compare(rhs) == 0; + } + friend Qt::strong_ordering compareThreeWay(const QCborArray &lhs, + const QCborArray &rhs) noexcept + { + int c = lhs.compare(rhs); + return Qt::compareThreeWay(c, 0); + } + Q_DECLARE_STRONGLY_ORDERED(QCborArray) + + friend bool comparesEqual(const QCborArray &lhs, + const QCborValueConstRef &rhs) noexcept + { + return lhs.compare(rhs.toArray()) == 0; + } + friend Qt::strong_ordering compareThreeWay(const QCborArray &lhs, + const QCborValueConstRef &rhs) noexcept + { + const int c = lhs.compare(rhs.toArray()); + return Qt::compareThreeWay(c, 0); + } + Q_DECLARE_STRONGLY_ORDERED(QCborArray, QCborValueConstRef) + void detach(qsizetype reserve = 0); friend QCborValue; |