From 3afd06cd43d78ef0992eaa6a458572eea6769297 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Thu, 29 Oct 2020 14:30:50 +0100 Subject: [PATCH] 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 +++++++++++++++-------------------- src/corelib/tools/qlist.qdoc | 28 ++++----- 2 files changed, 60 insertions(+), 78 deletions(-) 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 diff --git a/src/corelib/tools/qlist.qdoc b/src/corelib/tools/qlist.qdoc index abfbd23d91..591be76018 100644 --- a/src/corelib/tools/qlist.qdoc +++ b/src/corelib/tools/qlist.qdoc @@ -388,49 +388,45 @@ \sa operator==() */ -/*! \fn template bool operator<(const QList &lhs, const QList &rhs) +/*! \fn template bool QList::operator<(const QList &other) const \since 5.6 - \relates QList - Returns \c true if list \a lhs is + Returns \c true if this list is \l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare} - {lexicographically less than} \a rhs; otherwise returns \c false. + {lexicographically less than} \a other; otherwise returns \c false. This function requires the value type to have an implementation of \c operator<(). */ -/*! \fn template bool operator<=(const QList &lhs, const QList &rhs) +/*! \fn template bool QList::operator<=(const QList &other) const \since 5.6 - \relates QList - Returns \c true if list \a lhs is + Returns \c true if this list is \l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare} - {lexicographically less than or equal to} \a rhs; otherwise returns \c false. + {lexicographically less than or equal to} \a other; otherwise returns \c false. This function requires the value type to have an implementation of \c operator<(). */ -/*! \fn template bool operator>(const QList &lhs, const QList &rhs) +/*! \fn template bool QList::operator>(const QList &other) \since 5.6 - \relates QList - Returns \c true if list \a lhs is + Returns \c true if this list is \l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare} - {lexicographically greater than} \a rhs; otherwise returns \c false. + {lexicographically greater than} \a other; otherwise returns \c false. This function requires the value type to have an implementation of \c operator<(). */ -/*! \fn template bool operator>=(const QList &lhs, const QList &rhs) +/*! \fn template bool QList::operator>=(const QList &other) \since 5.6 - \relates QList - Returns \c true if list \a lhs is + Returns \c true if this list is \l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare} - {lexicographically greater than or equal to} \a rhs; otherwise returns \c false. + {lexicographically greater than or equal to} \a other; otherwise returns \c false. This function requires the value type to have an implementation of \c operator<().