summaryrefslogtreecommitdiffstats
path: root/src/corelib/serialization/qcbormap.h
diff options
context:
space:
mode:
authorTatiana Borisova <tatiana.borisova@qt.io>2024-03-12 20:33:15 +0100
committerTatiana Borisova <tatiana.borisova@qt.io>2024-03-20 15:21:00 +0100
commite5ebb9022ab9e00ab01d0bce527755da77083217 (patch)
tree0bed612324c53537eacfe296a34461c11d75d4c2 /src/corelib/serialization/qcbormap.h
parentb7eb73b1f0b550c1697b70c3ab9ddb7480557faf (diff)
QCborMap: use new comparison helper macros
Replace public operators operator==(), operator!=(), operator<() of QCborMap 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(QCborMap, QCborValue) and compareThreeWay(QCborMap, QCborValue) to the QCborMap class, to support comparison between QCborMap and QCborValue elements, see test-case mapSelfAssign() -> QT_TEST_EQUALITY_OPS(it.key(), QCborMap({{0, v}}), true); Task-number: QTBUG-120300 Change-Id: I9e33df255d16484efd3124cf0632db859408fb5d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Diffstat (limited to 'src/corelib/serialization/qcbormap.h')
-rw-r--r--src/corelib/serialization/qcbormap.h38
1 files changed, 28 insertions, 10 deletions
diff --git a/src/corelib/serialization/qcbormap.h b/src/corelib/serialization/qcbormap.h
index f5a118d673..55935e113e 100644
--- a/src/corelib/serialization/qcbormap.h
+++ b/src/corelib/serialization/qcbormap.h
@@ -221,19 +221,11 @@ public:
{ const_iterator it = find(key); return it != end(); }
int compare(const QCborMap &other) const noexcept Q_DECL_PURE_FUNCTION;
-#if 0 && __has_include(<compare>)
- std::strong_ordering operator<=>(const QCborMap &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 QCborMap &other) const noexcept
{ return compare(other) == 0; }
bool operator!=(const QCborMap &other) const noexcept
- { return !(*this == other); }
+ { return !operator==(other); }
bool operator<(const QCborMap &other) const
{ return compare(other) < 0; }
#endif
@@ -308,6 +300,32 @@ private:
friend class QJsonPrivate::Variant;
void detach(qsizetype reserve = 0);
+ friend bool comparesEqual(const QCborMap &lhs, const QCborMap &rhs) noexcept
+ {
+ return lhs.compare(rhs) == 0;
+ }
+ friend Qt::strong_ordering compareThreeWay(const QCborMap &lhs,
+ const QCborMap &rhs) noexcept
+ {
+ int c = lhs.compare(rhs);
+ return Qt::compareThreeWay(c, 0);
+ }
+ Q_DECLARE_STRONGLY_ORDERED(QCborMap)
+
+ friend bool comparesEqual(const QCborMap &lhs,
+ const QCborValue &rhs) noexcept
+ {
+ return lhs.compare(rhs.toMap()) == 0;
+ }
+
+ friend Qt::strong_ordering compareThreeWay(const QCborMap &lhs,
+ const QCborValue &rhs) noexcept
+ {
+ int c = lhs.compare(rhs.toMap());
+ return Qt::compareThreeWay(c, 0);
+ }
+ Q_DECLARE_STRONGLY_ORDERED(QCborMap, QCborValue)
+
explicit QCborMap(QCborContainerPrivate &dd) noexcept;
QExplicitlySharedDataPointer<QCborContainerPrivate> d;
};