diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index 17fbe204a0..de26b06a5d 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -153,6 +153,13 @@ public: --s; } + template + qsizetype indexOf(const AT &t, qsizetype from = 0) const; + template + qsizetype lastIndexOf(const AT &t, qsizetype from = -1) const; + template + bool contains(const AT &t) const; + reference operator[](qsizetype idx) { verify(idx); @@ -164,6 +171,21 @@ public: return data()[idx]; } + value_type value(qsizetype i) const; + value_type value(qsizetype i, const T& defaultValue) const; + + void replace(qsizetype i, const T &t); + void remove(qsizetype i, qsizetype n = 1); + template + qsizetype removeAll(const AT &t); + template + bool removeOne(const AT &t); + template + qsizetype removeIf(Predicate pred); + + iterator erase(const_iterator begin, const_iterator end); + iterator erase(const_iterator pos) { return erase(pos, pos + 1); } + protected: bool isValidIterator(const const_iterator &i) const { @@ -324,12 +346,17 @@ public: #endif void reserve(qsizetype sz) { if (sz > capacity()) reallocate(size(), sz); } +#ifdef Q_QDOC 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; +#endif + using Base::indexOf; + using Base::lastIndexOf; + using Base::contains; #ifdef Q_QDOC inline T &operator[](qsizetype idx) @@ -346,8 +373,11 @@ public: using Base::operator[]; inline const T &at(qsizetype idx) const { return operator[](idx); } +#ifdef Q_QDOC T value(qsizetype i) const; T value(qsizetype i, const T &defaultValue) const; +#endif + using Base::value; inline void append(const T &t) { @@ -381,6 +411,7 @@ public: void insert(qsizetype i, T &&t); void insert(qsizetype i, const T &t); void insert(qsizetype i, qsizetype n, const T &t); +#ifdef Q_QDOC void replace(qsizetype i, const T &t); void remove(qsizetype i, qsizetype n = 1); template @@ -389,6 +420,12 @@ public: bool removeOne(const AT &t); template qsizetype removeIf(Predicate pred); +#endif + using Base::replace; + using Base::remove; + using Base::removeAll; + using Base::removeOne; + using Base::removeIf; #ifdef Q_QDOC inline T *data() { return this->ptr; } @@ -428,8 +465,11 @@ public: iterator insert(const_iterator before, qsizetype n, const T &x); iterator insert(const_iterator before, T &&x) { return emplace(before, std::move(x)); } inline iterator insert(const_iterator before, const T &x) { return insert(before, 1, x); } +#ifdef Q_QDOC iterator erase(const_iterator begin, const_iterator end); inline iterator erase(const_iterator pos) { return erase(pos, pos + 1); } +#endif + using Base::erase; // STL compatibility: #ifdef Q_QDOC @@ -544,9 +584,9 @@ Q_INLINE_TEMPLATE QVarLengthArray::QVarLengthArray(qsizetype asize) } } -template +template template -Q_INLINE_TEMPLATE qsizetype QVarLengthArray::indexOf(const AT &t, qsizetype from) const +Q_INLINE_TEMPLATE qsizetype QVLABase::indexOf(const AT &t, qsizetype from) const { if (from < 0) from = qMax(from + size(), qsizetype(0)); @@ -560,9 +600,9 @@ Q_INLINE_TEMPLATE qsizetype QVarLengthArray::indexOf(const AT &t, q return -1; } -template +template template -Q_INLINE_TEMPLATE qsizetype QVarLengthArray::lastIndexOf(const AT &t, qsizetype from) const +Q_INLINE_TEMPLATE qsizetype QVLABase::lastIndexOf(const AT &t, qsizetype from) const { if (from < 0) from += size(); @@ -579,9 +619,9 @@ Q_INLINE_TEMPLATE qsizetype QVarLengthArray::lastIndexOf(const AT & return -1; } -template +template template -Q_INLINE_TEMPLATE bool QVarLengthArray::contains(const AT &t) const +Q_INLINE_TEMPLATE bool QVLABase::contains(const AT &t) const { const T *b = begin(); const T *i = end(); @@ -669,15 +709,15 @@ Q_OUTOFLINE_TEMPLATE void QVarLengthArray::reallocate(qsizetype asi } -template -Q_OUTOFLINE_TEMPLATE T QVarLengthArray::value(qsizetype i) const +template +Q_OUTOFLINE_TEMPLATE T QVLABase::value(qsizetype i) const { if (size_t(i) >= size_t(size())) return T(); return operator[](i); } -template -Q_OUTOFLINE_TEMPLATE T QVarLengthArray::value(qsizetype i, const T &defaultValue) const +template +Q_OUTOFLINE_TEMPLATE T QVLABase::value(qsizetype i, const T &defaultValue) const { return (size_t(i) >= size_t(size())) ? defaultValue : operator[](i); } @@ -694,21 +734,21 @@ template inline void QVarLengthArray::insert(qsizetype i, qsizetype n, const T &t) { verify(i, 0); insert(begin() + i, n, t); } -template -inline void QVarLengthArray::remove(qsizetype i, qsizetype n) +template +inline void QVLABase::remove(qsizetype i, qsizetype n) { verify(i, n); erase(begin() + i, begin() + i + n); } -template +template template -inline qsizetype QVarLengthArray::removeAll(const AT &t) +inline qsizetype QVLABase::removeAll(const AT &t) { return QtPrivate::sequential_erase_with_copy(*this, t); } -template +template template -inline bool QVarLengthArray::removeOne(const AT &t) +inline bool QVLABase::removeOne(const AT &t) { return QtPrivate::sequential_erase_one(*this, t); } -template +template template -inline qsizetype QVarLengthArray::removeIf(Predicate pred) +inline qsizetype QVLABase::removeIf(Predicate pred) { return QtPrivate::sequential_erase_if(*this, pred); } #if QT_DEPRECATED_SINCE(6, 3) template @@ -719,8 +759,8 @@ inline void QVarLengthArray::prepend(const T &t) { insert(begin(), 1, t); } #endif -template -inline void QVarLengthArray::replace(qsizetype i, const T &t) +template +inline void QVLABase::replace(qsizetype i, const T &t) { verify(i); data()[i] = t; @@ -788,8 +828,8 @@ Q_OUTOFLINE_TEMPLATE typename QVarLengthArray::iterator QVarLengthA return data() + offset; } -template -Q_OUTOFLINE_TEMPLATE typename QVarLengthArray::iterator QVarLengthArray::erase(const_iterator abegin, const_iterator aend) +template +Q_OUTOFLINE_TEMPLATE auto QVLABase::erase(const_iterator abegin, const_iterator aend) -> iterator { Q_ASSERT_X(isValidIterator(abegin), "QVarLengthArray::insert", "The specified const_iterator argument 'abegin' is invalid"); Q_ASSERT_X(isValidIterator(aend), "QVarLengthArray::insert", "The specified const_iterator argument 'aend' is invalid");