diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index 0bbee4f36e..b538cf292d 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -310,6 +310,68 @@ public: inline const T &back() const { return last(); } void shrink_to_fit() { squeeze(); } +#ifdef Q_QDOC + template + friend inline bool operator==(const QVarLengthArray &l, const QVarLengthArray &r); + template + friend inline bool operator!=(const QVarLengthArray &l, const QVarLengthArray &r); + template + friend inline bool operator< (const QVarLengthArray &l, const QVarLengthArray &r); + template + friend inline bool operator> (const QVarLengthArray &l, const QVarLengthArray &r); + template + friend inline bool operator<=(const QVarLengthArray &l, const QVarLengthArray &r); + template + friend inline bool operator>=(const QVarLengthArray &l, const QVarLengthArray &r); +#else + template friend + QTypeTraits::compare_eq_result operator==(const QVarLengthArray &l, const QVarLengthArray &r) + { + if (l.size() != r.size()) + return false; + const T *rb = r.begin(); + const T *b = l.begin(); + const T *e = l.end(); + return std::equal(b, e, QT_MAKE_CHECKED_ARRAY_ITERATOR(rb, r.size())); + } + + template friend + QTypeTraits::compare_eq_result operator!=(const QVarLengthArray &l, const QVarLengthArray &r) + { + return !(l == r); + } + + template friend + QTypeTraits::compare_lt_result operator<(const QVarLengthArray &lhs, const QVarLengthArray &rhs) + noexcept(noexcept(std::lexicographical_compare(lhs.begin(), lhs.end(), + rhs.begin(), rhs.end()))) + { + return std::lexicographical_compare(lhs.begin(), lhs.end(), + rhs.begin(), rhs.end()); + } + + template friend + QTypeTraits::compare_lt_result operator>(const QVarLengthArray &lhs, const QVarLengthArray &rhs) + noexcept(noexcept(lhs < rhs)) + { + return rhs < lhs; + } + + template friend + QTypeTraits::compare_lt_result operator<=(const QVarLengthArray &lhs, const QVarLengthArray &rhs) + noexcept(noexcept(lhs < rhs)) + { + return !(lhs > rhs); + } + + template friend + QTypeTraits::compare_lt_result operator>=(const QVarLengthArray &lhs, const QVarLengthArray &rhs) + noexcept(noexcept(lhs < rhs)) + { + return !(lhs < rhs); + } +#endif + private: void reallocate(qsizetype size, qsizetype alloc); @@ -626,52 +688,27 @@ Q_OUTOFLINE_TEMPLATE typename QVarLengthArray::iterator QVarLengthA return ptr + f; } +#ifdef Q_QDOC +// Fake definitions for qdoc, only the redeclaration is used. template -QTypeTraits::compare_eq_result operator==(const QVarLengthArray &l, const QVarLengthArray &r) -{ - if (l.size() != r.size()) - return false; - const T *rb = r.begin(); - const T *b = l.begin(); - const T *e = l.end(); - return std::equal(b, e, QT_MAKE_CHECKED_ARRAY_ITERATOR(rb, r.size())); -} - +bool operator==(const QVarLengthArray &l, const QVarLengthArray &r) +{ return bool{}; } template -QTypeTraits::compare_eq_result operator!=(const QVarLengthArray &l, const QVarLengthArray &r) -{ - return !(l == r); -} - +bool operator!=(const QVarLengthArray &l, const QVarLengthArray &r) +{ return bool{}; } template -QTypeTraits::compare_lt_result operator<(const QVarLengthArray &lhs, const QVarLengthArray &rhs) - noexcept(noexcept(std::lexicographical_compare(lhs.begin(), lhs.end(), - rhs.begin(), rhs.end()))) -{ - return std::lexicographical_compare(lhs.begin(), lhs.end(), - rhs.begin(), rhs.end()); -} - +bool operator< (const QVarLengthArray &l, const QVarLengthArray &r) +{ return bool{}; } template -QTypeTraits::compare_lt_result operator>(const QVarLengthArray &lhs, const QVarLengthArray &rhs) - noexcept(noexcept(lhs < rhs)) -{ - return rhs < lhs; -} - +bool operator> (const QVarLengthArray &l, const QVarLengthArray &r) +{ return bool{}; } template -QTypeTraits::compare_lt_result operator<=(const QVarLengthArray &lhs, const QVarLengthArray &rhs) - noexcept(noexcept(lhs < rhs)) -{ - return !(lhs > rhs); -} - +bool operator<=(const QVarLengthArray &l, const QVarLengthArray &r) +{ return bool{}; } template -QTypeTraits::compare_lt_result operator>=(const QVarLengthArray &lhs, const QVarLengthArray &rhs) - noexcept(noexcept(lhs < rhs)) -{ - return !(lhs < rhs); -} +bool operator>=(const QVarLengthArray &l, const QVarLengthArray &r) +{ return bool{}; } +#endif template size_t qHash(const QVarLengthArray &key, size_t seed = 0) diff --git a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp index 5c5ccf0a21..70a59e974f 100644 --- a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp +++ b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp @@ -877,11 +877,11 @@ void tst_QVarLengthArray::squeeze() void tst_QVarLengthArray::operators() { - QVarLengthArray myvla; + QVarLengthArray myvla; myvla << "A" << "B" << "C"; - QVarLengthArray myvlatwo; + QVarLengthArray myvlatwo; myvlatwo << "D" << "E" << "F"; - QVarLengthArray combined; + QVarLengthArray combined; combined << "A" << "B" << "C" << "D" << "E" << "F"; // !=