diff options
Diffstat (limited to 'src/corelib/serialization/qjsonarray.h')
-rw-r--r-- | src/corelib/serialization/qjsonarray.h | 93 |
1 files changed, 84 insertions, 9 deletions
diff --git a/src/corelib/serialization/qjsonarray.h b/src/corelib/serialization/qjsonarray.h index a2baa7738c..26a04e9196 100644 --- a/src/corelib/serialization/qjsonarray.h +++ b/src/corelib/serialization/qjsonarray.h @@ -94,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; } @@ -123,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; }; @@ -152,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; } @@ -172,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; }; |