From f87c027931691d5bc658cc3855efe8b83b5c9182 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Fri, 16 Oct 2020 16:15:02 +0200 Subject: 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 --- src/corelib/tools/qvarlengtharray.h | 18 ++++++++++++------ src/corelib/tools/qvarlengtharray.qdoc | 6 +++--- 2 files changed, 15 insertions(+), 9 deletions(-) (limited to 'src/corelib') 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 + inline qsizetype indexOf(const AT &t, qsizetype from = 0) const; + template + inline qsizetype lastIndexOf(const AT &t, qsizetype from = -1) const; + template + 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::reserve(qsizetype asize) { if (asize > a) reallocate(s, asize); } template -Q_INLINE_TEMPLATE qsizetype QVarLengthArray::indexOf(const T &t, qsizetype from) const +template +Q_INLINE_TEMPLATE qsizetype QVarLengthArray::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::indexOf(const T &t, qs } template -Q_INLINE_TEMPLATE qsizetype QVarLengthArray::lastIndexOf(const T &t, qsizetype from) const +template +Q_INLINE_TEMPLATE qsizetype QVarLengthArray::lastIndexOf(const AT &t, qsizetype from) const { if (from < 0) from += s; @@ -371,7 +376,8 @@ Q_INLINE_TEMPLATE qsizetype QVarLengthArray::lastIndexOf(const T &t } template -Q_INLINE_TEMPLATE bool QVarLengthArray::contains(const T &t) const +template +Q_INLINE_TEMPLATE bool QVarLengthArray::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 qsizetype QVarLengthArray::indexOf(const T &value, qsizetype from = 0) const +/*! \fn template template qsizetype QVarLengthArray::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 qsizetype QVarLengthArray::lastIndexOf(const T &value, qsizetype from = -1) const +/*! \fn template template qsizetype QVarLengthArray::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 bool QVarLengthArray::contains(const T &value) const +/*! \fn template template bool QVarLengthArray::contains(const AT &value) const \since 5.3 Returns \c true if the array contains an occurrence of \a value; -- cgit v1.2.3