summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-29 14:30:50 +0100
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2020-10-30 08:20:16 +0100
commit3afd06cd43d78ef0992eaa6a458572eea6769297 (patch)
tree61f3572d09675baa7dc38878e39d47f5601fe0e2
parent0575ff787a723e39ac69cf2f389161134ce4e6ba (diff)
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 <qt_ci_bot@qt-project.org> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
-rw-r--r--src/corelib/tools/qlist.h110
-rw-r--r--src/corelib/tools/qlist.qdoc28
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<T> &other) const;
- bool operator!=(const QList<T> &other) const;
-#endif
-
void swap(QList<T> &other) noexcept { qSwap(d, other.d); }
- template <typename U>
- friend QTypeTraits::compare_eq_result<U> operator==(const QList<U> &l, const QList<U> &r);
- template <typename U>
- friend QTypeTraits::compare_eq_result<U> operator!=(const QList<U> &l, const QList<U> &r);
+ template <typename U = T>
+ QTypeTraits::compare_eq_result<U> 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 <typename U = T>
+ QTypeTraits::compare_eq_result<U> operator!=(const QList &other) const
+ {
+ return !(*this == other);
+ }
+
+ template <typename U = T>
+ QTypeTraits::compare_lt_result<U> operator<(const QList &other) const
+ noexcept(noexcept(std::lexicographical_compare<typename QList<U>::const_iterator,
+ typename QList::const_iterator>(
+ std::declval<QList<U>>().begin(), std::declval<QList<U>>().end(),
+ other.begin(), other.end())))
+ {
+ return std::lexicographical_compare(begin(), end(),
+ other.begin(), other.end());
+ }
+
+ template <typename U = T>
+ QTypeTraits::compare_lt_result<U> operator>(const QList &other) const
+ noexcept(noexcept(other < std::declval<QList<U>>()))
+ {
+ return other < *this;
+ }
+
+ template <typename U = T>
+ QTypeTraits::compare_lt_result<U> operator<=(const QList &other) const
+ noexcept(noexcept(other < std::declval<QList<U>>()))
+ {
+ return !(other < *this);
+ }
+
+ template <typename U = T>
+ QTypeTraits::compare_lt_result<U> operator>=(const QList &other) const
+ noexcept(noexcept(std::declval<QList<U>>() < 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<T> &key, size_t seed = 0)
return qHashRange(key.cbegin(), key.cend(), seed);
}
-template <typename U>
-QTypeTraits::compare_eq_result<U> operator==(const QList<U> &l, const QList<U> &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 <typename U>
-QTypeTraits::compare_eq_result<U> operator!=(const QList<U> &l, const QList<U> &r)
-{
- return !(l == r);
-}
-
-template <typename T>
-auto operator<(const QList<T> &lhs, const QList<T> &rhs)
- noexcept(noexcept(std::lexicographical_compare(lhs.begin(), lhs.end(),
- rhs.begin(), rhs.end())))
- -> decltype(std::declval<T>() < std::declval<T>())
-{
- return std::lexicographical_compare(lhs.begin(), lhs.end(),
- rhs.begin(), rhs.end());
-}
-
-template <typename T>
-auto operator>(const QList<T> &lhs, const QList<T> &rhs)
- noexcept(noexcept(lhs < rhs))
- -> decltype(lhs < rhs)
-{
- return rhs < lhs;
-}
-
-template <typename T>
-auto operator<=(const QList<T> &lhs, const QList<T> &rhs)
- noexcept(noexcept(lhs < rhs))
- -> decltype(lhs < rhs)
-{
- return !(lhs > rhs);
-}
-
-template <typename T>
-auto operator>=(const QList<T> &lhs, const QList<T> &rhs)
- noexcept(noexcept(lhs < rhs))
- -> decltype(lhs < rhs)
-{
- return !(lhs < rhs);
-}
-
QList<uint> 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 <typename T> bool operator<(const QList<T> &lhs, const QList<T> &rhs)
+/*! \fn template <typename T> bool QList<T>::operator<(const QList<T> &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 <typename T> bool operator<=(const QList<T> &lhs, const QList<T> &rhs)
+/*! \fn template <typename T> bool QList<T>::operator<=(const QList<T> &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 <typename T> bool operator>(const QList<T> &lhs, const QList<T> &rhs)
+/*! \fn template <typename T> bool QList<T>::operator>(const QList<T> &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 <typename T> bool operator>=(const QList<T> &lhs, const QList<T> &rhs)
+/*! \fn template <typename T> bool QList<T>::operator>=(const QList<T> &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<().