diff options
Diffstat (limited to 'src/corelib/serialization/qjsonarray.h')
-rw-r--r-- | src/corelib/serialization/qjsonarray.h | 104 |
1 files changed, 94 insertions, 10 deletions
diff --git a/src/corelib/serialization/qjsonarray.h b/src/corelib/serialization/qjsonarray.h index af4ac9fd37..26a04e9196 100644 --- a/src/corelib/serialization/qjsonarray.h +++ b/src/corelib/serialization/qjsonarray.h @@ -60,9 +60,10 @@ public: QJsonValueRef operator[](qsizetype i); QJsonValue operator[](qsizetype i) const; +#if QT_CORE_REMOVED_SINCE(6, 8) bool operator==(const QJsonArray &other) const; bool operator!=(const QJsonArray &other) const; - +#endif void swap(QJsonArray &other) noexcept { a.swap(other.a); @@ -93,24 +94,26 @@ public: inline QJsonValueRef *operator->() { return &item; } inline QJsonValueRef operator[](qsizetype j) const { return *(*this + j); } +#if QT_CORE_REMOVED_SINCE(6, 8) inline bool operator==(const iterator &o) const { return item.d == o.item.d && item.index == o.item.index; } - inline bool operator!=(const iterator &o) const { return !(*this == o); } + inline bool operator!=(const iterator &o) const { return !operator==(o); } inline bool operator<(const iterator &other) const { Q_ASSERT(item.d == other.item.d); return item.index < other.item.index; } inline bool operator<=(const iterator &other) const { Q_ASSERT(item.d == other.item.d); return item.index <= other.item.index; } - inline bool operator>(const iterator &other) const { return !(*this <= other); } - inline bool operator>=(const iterator &other) const { return !(*this < other); } + inline bool operator>(const iterator &other) const { return !operator<=(other); } + inline bool operator>=(const iterator &other) const { return !operator<(other); } inline bool operator==(const const_iterator &o) const { return item.d == o.item.d && item.index == o.item.index; } - inline bool operator!=(const const_iterator &o) const { return !(*this == o); } + inline bool operator!=(const const_iterator &o) const { return !operator==(o); } inline bool operator<(const const_iterator &other) const { Q_ASSERT(item.d == other.item.d); return item.index < other.item.index; } inline bool operator<=(const const_iterator &other) const { Q_ASSERT(item.d == other.item.d); return item.index <= other.item.index; } - inline bool operator>(const const_iterator &other) const { return !(*this <= other); } - inline bool operator>=(const const_iterator &other) const { return !(*this < other); } + inline bool operator>(const const_iterator &other) const { return !operator<=(other); } + inline bool operator>=(const const_iterator &other) const { return !operator<(other); } +#endif inline iterator &operator++() { ++item.index; return *this; } inline iterator operator++(int) { iterator n = *this; ++item.index; return n; } inline iterator &operator--() { item.index--; return *this; } @@ -122,6 +125,53 @@ public: inline qsizetype operator-(iterator j) const { return item.index - j.item.index; } private: + // Helper functions + static bool comparesEqual_helper(const iterator &lhs, const iterator &rhs) noexcept + { + return lhs.item.d == rhs.item.d && lhs.item.index == rhs.item.index; + } + + static bool comparesEqual_helper(const iterator &lhs, const const_iterator &rhs) noexcept + { + return lhs.item.d == rhs.item.d && lhs.item.index == rhs.item.index; + } + + static Qt::strong_ordering compareThreeWay_helper(const iterator &lhs, + const iterator &rhs) noexcept + { + Q_ASSERT(lhs.item.d == rhs.item.d); + return Qt::compareThreeWay(lhs.item.index, rhs.item.index); + } + + static Qt::strong_ordering compareThreeWay_helper(const iterator &lhs, + const const_iterator &rhs) noexcept + { + Q_ASSERT(lhs.item.d == rhs.item.d); + return Qt::compareThreeWay(lhs.item.index, rhs.item.index); + } + + // Compare friends + friend bool comparesEqual(const iterator &lhs, const iterator &rhs) noexcept + { + return comparesEqual_helper(lhs, rhs); + } + friend Qt::strong_ordering compareThreeWay(const iterator &lhs, + const iterator &rhs) noexcept + { + return compareThreeWay_helper(lhs, rhs); + } + Q_DECLARE_STRONGLY_ORDERED(iterator) + friend bool comparesEqual(const iterator &lhs, const const_iterator &rhs) noexcept + { + return comparesEqual_helper(lhs, rhs); + } + friend Qt::strong_ordering compareThreeWay(const iterator &lhs, + const const_iterator &rhs) noexcept + { + return compareThreeWay_helper(lhs, rhs); + } + Q_DECLARE_STRONGLY_ORDERED(iterator, const_iterator) + QJsonValueRef item; friend class QJsonArray; }; @@ -151,15 +201,17 @@ public: inline const QJsonValueConstRef *operator->() const { return &item; } inline QJsonValueConstRef operator[](qsizetype j) const { return *(*this + j); } +#if QT_CORE_REMOVED_SINCE(6, 8) inline bool operator==(const const_iterator &o) const { return item.d == o.item.d && item.index == o.item.index; } - inline bool operator!=(const const_iterator &o) const { return !(*this == o); } + inline bool operator!=(const const_iterator &o) const { return !operator==(o); } inline bool operator<(const const_iterator &other) const { Q_ASSERT(item.d == other.item.d); return item.index < other.item.index; } inline bool operator<=(const const_iterator &other) const { Q_ASSERT(item.d == other.item.d); return item.index <= other.item.index; } - inline bool operator>(const const_iterator &other) const { return !(*this <= other); } - inline bool operator>=(const const_iterator &other) const { return !(*this < other); } + inline bool operator>(const const_iterator &other) const { return !operator<=(other); } + inline bool operator>=(const const_iterator &other) const { return !operator<(other); } +#endif inline const_iterator &operator++() { ++item.index; return *this; } inline const_iterator operator++(int) { const_iterator n = *this; ++item.index; return n; } inline const_iterator &operator--() { item.index--; return *this; } @@ -171,6 +223,30 @@ public: inline qsizetype operator-(const_iterator j) const { return item.index - j.item.index; } private: + // Helper functions + static bool comparesEqual_helper(const const_iterator &lhs, + const const_iterator &rhs) noexcept + { + return lhs.item.d == rhs.item.d && lhs.item.index == rhs.item.index; + } + static Qt::strong_ordering compareThreeWay_helper(const const_iterator &lhs, + const const_iterator &rhs) noexcept + { + Q_ASSERT(lhs.item.d == rhs.item.d); + return Qt::compareThreeWay(lhs.item.index, rhs.item.index); + } + + // Compare friends + friend bool comparesEqual(const const_iterator &lhs, const const_iterator &rhs) noexcept + { + return comparesEqual_helper(lhs, rhs); + } + friend Qt::strong_ordering compareThreeWay(const const_iterator &lhs, + const const_iterator &rhs) noexcept + { + return compareThreeWay_helper(lhs, rhs); + } + Q_DECLARE_STRONGLY_ORDERED(const_iterator) QJsonValueConstRef item; friend class QJsonArray; }; @@ -225,6 +301,14 @@ private: friend class QCborArray; friend Q_CORE_EXPORT QDebug operator<<(QDebug, const QJsonArray &); + friend Q_CORE_EXPORT bool comparesEqual(const QJsonArray &lhs, + const QJsonArray &rhs) noexcept; + + friend Q_CORE_EXPORT bool comparesEqual(const QJsonArray &lhs, + const QJsonValue &rhs) noexcept; + Q_DECLARE_EQUALITY_COMPARABLE(QJsonArray) + Q_DECLARE_EQUALITY_COMPARABLE(QJsonArray, QJsonValue) + QJsonArray(QCborContainerPrivate *array); bool detach(qsizetype reserve = 0); |