summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qlist.h
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-06-05 21:01:29 +0200
committerLars Knoll <lars.knoll@qt.io>2020-07-08 14:13:56 +0200
commit0e2cfdedf261a9d29d7466bd26545549479d9f8a (patch)
tree8c6b3eaaad7463bf2e019b0694286aa065544138 /src/corelib/tools/qlist.h
parent16bc995fd1eba4f7485226f319e7736ca19040bc (diff)
Constrain the comparison operators for our container classes
This had already been in very few places, where we ran into issues with this before. More generic constraints here will significantly reduce the amount of error messages a user has to parse in case he tries to instantiate an operator by accident (or with a lacking comparison operator for one of it's template arguments). Change-Id: I1521d19c55d99732d9742402bd534c390a8e4242 Reviewed-by: Paul Wicking <paul.wicking@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qlist.h')
-rw-r--r--src/corelib/tools/qlist.h6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h
index 3b9eb154ed..c2e5e12a1d 100644
--- a/src/corelib/tools/qlist.h
+++ b/src/corelib/tools/qlist.h
@@ -162,7 +162,8 @@ public:
void swap(QList<T> &other) noexcept { qSwap(d, other.d); }
- friend bool operator==(const QList &l, const QList &r)
+ template <typename U = T>
+ friend QTypeTraits::compare_eq_result<U> operator==(const QList &l, const QList &r)
{
if (l.size() != r.size())
return false;
@@ -172,7 +173,8 @@ public:
// do element-by-element comparison
return l.d->compare(l.begin(), r.begin(), l.size());
}
- friend bool operator!=(const QList &l, const QList &r)
+ template <typename U = T>
+ friend QTypeTraits::compare_eq_result<U> operator!=(const QList &l, const QList &r)
{
return !(l == r);
}