From 3afd06cd43d78ef0992eaa6a458572eea6769297 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Thu, 29 Oct 2020 14:30:50 +0100 Subject: Hide QList comparisons from ADL Makes them member methods instead of hidden inline, as those actually gets listed in documentation, and two were already documented as such. Task-number: QTBUG-87975 Change-Id: I382ff8b701753f1fe150a38f4c530a52c98ad292 Reviewed-by: Qt CI Bot Reviewed-by: Volker Hilsheimer --- src/corelib/tools/qlist.h | 110 ++++++++++++++++++++-------------------------- 1 file changed, 48 insertions(+), 62 deletions(-) (limited to 'src/corelib/tools/qlist.h') diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 58676eeb1f..96efe28a31 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -204,18 +204,56 @@ public: // compiler-generated special member functions are fine! -#ifdef Q_QDOC - // extra missing ones: - bool operator==(const QList &other) const; - bool operator!=(const QList &other) const; -#endif - void swap(QList &other) noexcept { qSwap(d, other.d); } - template - friend QTypeTraits::compare_eq_result operator==(const QList &l, const QList &r); - template - friend QTypeTraits::compare_eq_result operator!=(const QList &l, const QList &r); + template + QTypeTraits::compare_eq_result operator==(const QList &other) const + { + if (size() != other.size()) + return false; + if (begin() == other.begin()) + return true; + + // do element-by-element comparison + return d->compare(begin(), other.begin(), size()); + } + template + QTypeTraits::compare_eq_result operator!=(const QList &other) const + { + return !(*this == other); + } + + template + QTypeTraits::compare_lt_result operator<(const QList &other) const + noexcept(noexcept(std::lexicographical_compare::const_iterator, + typename QList::const_iterator>( + std::declval>().begin(), std::declval>().end(), + other.begin(), other.end()))) + { + return std::lexicographical_compare(begin(), end(), + other.begin(), other.end()); + } + + template + QTypeTraits::compare_lt_result operator>(const QList &other) const + noexcept(noexcept(other < std::declval>())) + { + return other < *this; + } + + template + QTypeTraits::compare_lt_result operator<=(const QList &other) const + noexcept(noexcept(other < std::declval>())) + { + return !(other < *this); + } + + template + QTypeTraits::compare_lt_result operator>=(const QList &other) const + noexcept(noexcept(std::declval>() < other)) + { + return !(*this < other); + } qsizetype size() const noexcept { return d->size; } qsizetype count() const noexcept { return size(); } @@ -856,58 +894,6 @@ size_t qHash(const QList &key, size_t seed = 0) return qHashRange(key.cbegin(), key.cend(), seed); } -template -QTypeTraits::compare_eq_result operator==(const QList &l, const QList &r) -{ - if (l.size() != r.size()) - return false; - if (l.begin() == r.begin()) - return true; - - // do element-by-element comparison - return l.d->compare(l.begin(), r.begin(), l.size()); -} - -template -QTypeTraits::compare_eq_result operator!=(const QList &l, const QList &r) -{ - return !(l == r); -} - -template -auto operator<(const QList &lhs, const QList &rhs) - noexcept(noexcept(std::lexicographical_compare(lhs.begin(), lhs.end(), - rhs.begin(), rhs.end()))) - -> decltype(std::declval() < std::declval()) -{ - return std::lexicographical_compare(lhs.begin(), lhs.end(), - rhs.begin(), rhs.end()); -} - -template -auto operator>(const QList &lhs, const QList &rhs) - noexcept(noexcept(lhs < rhs)) - -> decltype(lhs < rhs) -{ - return rhs < lhs; -} - -template -auto operator<=(const QList &lhs, const QList &rhs) - noexcept(noexcept(lhs < rhs)) - -> decltype(lhs < rhs) -{ - return !(lhs > rhs); -} - -template -auto operator>=(const QList &lhs, const QList &rhs) - noexcept(noexcept(lhs < rhs)) - -> decltype(lhs < rhs) -{ - return !(lhs < rhs); -} - QList QStringView::toUcs4() const { return QtPrivate::convertToUcs4(*this); } QT_END_NAMESPACE -- cgit v1.2.3