summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qcontiguouscache.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/qcontiguouscache.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/qcontiguouscache.h')
-rw-r--r--src/corelib/tools/qcontiguouscache.h37
1 files changed, 19 insertions, 18 deletions
diff --git a/src/corelib/tools/qcontiguouscache.h b/src/corelib/tools/qcontiguouscache.h
index 81361f219a..79f5e3fdb6 100644
--- a/src/corelib/tools/qcontiguouscache.h
+++ b/src/corelib/tools/qcontiguouscache.h
@@ -97,8 +97,25 @@ public:
inline QContiguousCache<T> &operator=(QContiguousCache<T> &&other) noexcept
{ qSwap(d, other.d); return *this; }
inline void swap(QContiguousCache<T> &other) noexcept { qSwap(d, other.d); }
- bool operator==(const QContiguousCache<T> &other) const;
- inline bool operator!=(const QContiguousCache<T> &other) const { return !(*this == other); }
+
+ template <typename U = T>
+ QTypeTraits::compare_eq_result<U> operator==(const QContiguousCache<T> &other) const
+ {
+ if (other.d == d)
+ return true;
+ if (other.d->start != d->start
+ || other.d->count != d->count
+ || other.d->offset != d->offset
+ || other.d->alloc != d->alloc)
+ return false;
+ for (qsizetype i = firstIndex(); i <= lastIndex(); ++i)
+ if (!(at(i) == other.at(i)))
+ return false;
+ return true;
+ }
+ template <typename U = T>
+ QTypeTraits::compare_eq_result<U> operator!=(const QContiguousCache<T> &other) const
+ { return !(*this == other); }
inline qsizetype capacity() const {return d->alloc; }
inline qsizetype count() const { return d->count; }
@@ -272,22 +289,6 @@ QContiguousCache<T> &QContiguousCache<T>::operator=(const QContiguousCache<T> &o
}
template <typename T>
-bool QContiguousCache<T>::operator==(const QContiguousCache<T> &other) const
-{
- if (other.d == d)
- return true;
- if (other.d->start != d->start
- || other.d->count != d->count
- || other.d->offset != d->offset
- || other.d->alloc != d->alloc)
- return false;
- for (qsizetype i = firstIndex(); i <= lastIndex(); ++i)
- if (!(at(i) == other.at(i)))
- return false;
- return true;
-}
-
-template <typename T>
void QContiguousCache<T>::freeData(Data *x)
{
if (QTypeInfo<T>::isComplex) {