diff options
author | Lars Knoll <lars.knoll@qt.io> | 2020-06-05 21:01:29 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2020-07-08 14:13:56 +0200 |
commit | 0e2cfdedf261a9d29d7466bd26545549479d9f8a (patch) | |
tree | 8c6b3eaaad7463bf2e019b0694286aa065544138 /src/corelib/tools/qhash.h | |
parent | 16bc995fd1eba4f7485226f319e7736ca19040bc (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/qhash.h')
-rw-r--r-- | src/corelib/tools/qhash.h | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index 2de3989eb2..8825372c03 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -782,7 +782,8 @@ public: #endif void swap(QHash &other) noexcept { qSwap(d, other.d); } - bool operator==(const QHash &other) const noexcept + template <typename U = T> + QTypeTraits::compare_eq_result<U> operator==(const QHash &other) const noexcept { if (d == other.d) return true; @@ -797,7 +798,9 @@ public: // all values must be the same as size is the same return true; } - bool operator!=(const QHash &other) const noexcept { return !(*this == other); } + template <typename U = T> + QTypeTraits::compare_eq_result<U> operator!=(const QHash &other) const noexcept + { return !(*this == other); } inline qsizetype size() const noexcept { return d ? qsizetype(d->size) : 0; } inline bool isEmpty() const noexcept { return !d || d->size == 0; } |