summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qlist.h
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 /src/corelib/tools/qlist.h
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>
Diffstat (limited to 'src/corelib/tools/qlist.h')
-rw-r--r--src/corelib/tools/qlist.h110
1 files changed, 48 insertions, 62 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