diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2020-10-16 16:15:02 +0200 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2020-10-19 16:29:49 +0200 |
commit | f87c027931691d5bc658cc3855efe8b83b5c9182 (patch) | |
tree | fdec778cf7cd4c81f35be1ea992605aebe3427cc /src/corelib/tools | |
parent | 28df51caff7ad68b49c1af14e5907828cb97e937 (diff) |
QVLA: make (last)IndexOf and contains function templates
Just like QList.
[ChangeLog][QtCore][QVarLengthArray] The indexOf, lastIndexOf and contains
methods now take an object of any datatype -- and not just the
array's own value type. This allows for heterogenous lookup in
QVarLengthArray objects.
Change-Id: Ibc55191a140612a4e9be46b4d18457415ea3717f
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r-- | src/corelib/tools/qvarlengtharray.h | 18 | ||||
-rw-r--r-- | src/corelib/tools/qvarlengtharray.qdoc | 6 |
2 files changed, 15 insertions, 9 deletions
diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index b240f8d450..a3a07887d3 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -172,9 +172,12 @@ public: inline qsizetype capacity() const { return a; } inline void reserve(qsizetype size); - inline qsizetype indexOf(const T &t, qsizetype from = 0) const; - inline qsizetype lastIndexOf(const T &t, qsizetype from = -1) const; - inline bool contains(const T &t) const; + template <typename AT> + inline qsizetype indexOf(const AT &t, qsizetype from = 0) const; + template <typename AT> + inline qsizetype lastIndexOf(const AT &t, qsizetype from = -1) const; + template <typename AT> + inline bool contains(const AT &t) const; inline T &operator[](qsizetype idx) { Q_ASSERT(idx >= 0 && idx < s); @@ -338,7 +341,8 @@ Q_INLINE_TEMPLATE void QVarLengthArray<T, Prealloc>::reserve(qsizetype asize) { if (asize > a) reallocate(s, asize); } template <class T, qsizetype Prealloc> -Q_INLINE_TEMPLATE qsizetype QVarLengthArray<T, Prealloc>::indexOf(const T &t, qsizetype from) const +template <typename AT> +Q_INLINE_TEMPLATE qsizetype QVarLengthArray<T, Prealloc>::indexOf(const AT &t, qsizetype from) const { if (from < 0) from = qMax(from + s, qsizetype(0)); @@ -353,7 +357,8 @@ Q_INLINE_TEMPLATE qsizetype QVarLengthArray<T, Prealloc>::indexOf(const T &t, qs } template <class T, qsizetype Prealloc> -Q_INLINE_TEMPLATE qsizetype QVarLengthArray<T, Prealloc>::lastIndexOf(const T &t, qsizetype from) const +template <typename AT> +Q_INLINE_TEMPLATE qsizetype QVarLengthArray<T, Prealloc>::lastIndexOf(const AT &t, qsizetype from) const { if (from < 0) from += s; @@ -371,7 +376,8 @@ Q_INLINE_TEMPLATE qsizetype QVarLengthArray<T, Prealloc>::lastIndexOf(const T &t } template <class T, qsizetype Prealloc> -Q_INLINE_TEMPLATE bool QVarLengthArray<T, Prealloc>::contains(const T &t) const +template <typename AT> +Q_INLINE_TEMPLATE bool QVarLengthArray<T, Prealloc>::contains(const AT &t) const { T *b = ptr; T *i = ptr + s; diff --git a/src/corelib/tools/qvarlengtharray.qdoc b/src/corelib/tools/qvarlengtharray.qdoc index 5970081d85..99349d0b3d 100644 --- a/src/corelib/tools/qvarlengtharray.qdoc +++ b/src/corelib/tools/qvarlengtharray.qdoc @@ -874,7 +874,7 @@ \sa append(), operator<<() */ -/*! \fn template<class T, qsizetype Prealloc> qsizetype QVarLengthArray<T, Prealloc>::indexOf(const T &value, qsizetype from = 0) const +/*! \fn template<class T, qsizetype Prealloc> template <typename AT> qsizetype QVarLengthArray<T, Prealloc>::indexOf(const AT &value, qsizetype from = 0) const \since 5.3 Returns the index position of the first occurrence of \a value in @@ -887,7 +887,7 @@ \sa lastIndexOf(), contains() */ -/*! \fn template<class T, qsizetype Prealloc> qsizetype QVarLengthArray<T, Prealloc>::lastIndexOf(const T &value, qsizetype from = -1) const +/*! \fn template<class T, qsizetype Prealloc> template <typename AT> qsizetype QVarLengthArray<T, Prealloc>::lastIndexOf(const AT &value, qsizetype from = -1) const \since 5.3 Returns the index position of the last occurrence of the value \a @@ -901,7 +901,7 @@ \sa indexOf(), contains() */ -/*! \fn template<class T, qsizetype Prealloc> bool QVarLengthArray<T, Prealloc>::contains(const T &value) const +/*! \fn template<class T, qsizetype Prealloc> template <typename AT> bool QVarLengthArray<T, Prealloc>::contains(const AT &value) const \since 5.3 Returns \c true if the array contains an occurrence of \a value; |