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>
This commit is contained in:
parent
28df51caff
commit
f87c027931
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user