/**************************************************************************** ** ** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see https://www.qt.io/terms-conditions. For further ** information use the contact form at https://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 3 as published by the Free Software ** Foundation and appearing in the file LICENSE.LGPL3 included in the ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 3 requirements ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 2.0 or (at your option) the GNU General ** Public license version 3 or any later version approved by the KDE Free ** Qt Foundation. The licenses are as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 ** included in the packaging of this file. Please review the following ** information to ensure the GNU General Public License requirements will ** be met: https://www.gnu.org/licenses/gpl-2.0.html and ** https://www.gnu.org/licenses/gpl-3.0.html. ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #ifndef QVARLENGTHARRAY_H #define QVARLENGTHARRAY_H #if 0 #pragma qt_class(QVarLengthArray) #pragma qt_sync_stop_processing #endif #include #include #include #include #include #include #include #include #include #include #include #include QT_BEGIN_NAMESPACE template class QVLAStorage { template class print; protected: ~QVLAStorage() = default; alignas(Align) char array[Prealloc * (Align > Size ? Align : Size)]; QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED // ensure we maintain BC: std::aligned_storage_t was only specified by a // minimum size, but for BC we need the substitution to be exact in size: static_assert(std::is_same_v[Prealloc])>, print>); QT_WARNING_POP }; class QVLABaseBase { protected: ~QVLABaseBase() = default; qsizetype a; // capacity qsizetype s; // size void *ptr; // data Q_ALWAYS_INLINE constexpr void verify(qsizetype pos = 0, qsizetype n = 1) const { Q_ASSERT(pos >= 0); Q_ASSERT(pos <= size()); Q_ASSERT(n >= 0); Q_ASSERT(n <= size() - pos); } public: using size_type = qsizetype; constexpr size_type capacity() const noexcept { return a; } constexpr size_type size() const noexcept { return s; } constexpr bool empty() const noexcept { return size() == 0; } }; template class QVLABase : public QVLABaseBase { protected: ~QVLABase() = default; public: T *data() noexcept { return static_cast(ptr); } const T *data() const noexcept { return static_cast(ptr); } using iterator = T*; using const_iterator = const T*; iterator begin() noexcept { return data(); } const_iterator begin() const noexcept { return data(); } const_iterator cbegin() const noexcept { return begin(); } iterator end() noexcept { return data() + size(); } const_iterator end() const noexcept { return data() + size(); } const_iterator cend() const noexcept { return end(); } using reverse_iterator = std::reverse_iterator; using const_reverse_iterator = std::reverse_iterator; reverse_iterator rbegin() noexcept { return reverse_iterator{end()}; } const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator{end()}; } const_reverse_iterator crbegin() const noexcept { return rbegin(); } reverse_iterator rend() noexcept { return reverse_iterator{begin()}; } const_reverse_iterator rend() const noexcept { return const_reverse_iterator{begin()}; } const_reverse_iterator crend() const noexcept { return rend(); } using value_type = T; using reference = value_type&; using const_reference = const value_type&; using pointer = value_type*; using const_pointer = const value_type*; using difference_type = qptrdiff; reference front() { verify(); return *begin(); } const_reference front() const { verify(); return *begin(); } reference back() { verify(); return *rbegin(); } const_reference back() const { verify(); return *rbegin(); } void pop_back() { verify(); if constexpr (QTypeInfo::isComplex) data()[size() - 1].~T(); --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); return data()[idx]; } const_reference operator[](qsizetype idx) const { verify(idx); 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); } size_t hash(size_t seed) const noexcept(QtPrivate::QNothrowHashable_v) { return qHashRange(begin(), end(), seed); } protected: template reference emplace_back_impl(qsizetype prealloc, void *array, Args&&...args) { if (size() == capacity()) // ie. size() != 0 reallocate_impl(prealloc, array, size(), size() << 1); reference r = *new (end()) T(std::forward(args)...); ++s; return r; } template iterator emplace_impl(qsizetype prealloc, void *array, const_iterator pos, Args&&...arg); iterator insert_impl(qsizetype prealloc, void *array, const_iterator pos, qsizetype n, const T &t); template bool equal(const QVLABase &other) const { return std::equal(begin(), end(), other.begin(), other.end()); } template bool less_than(const QVLABase &other) const { return std::lexicographical_compare(begin(), end(), other.begin(), other.end()); } void append_impl(qsizetype prealloc, void *array, const T *buf, qsizetype n); void reallocate_impl(qsizetype prealloc, void *array, qsizetype size, qsizetype alloc); void resize_impl(qsizetype prealloc, void *array, qsizetype sz) { reallocate_impl(prealloc, array, sz, qMax(sz, capacity())); } bool isValidIterator(const const_iterator &i) const { const std::less less = {}; return !less(cend(), i) && !less(i, cbegin()); } }; // Prealloc = 256 by default, specified in qcontainerfwd.h template class QVarLengthArray : public QVLABase, // ### Qt 7: swap base class order public QVLAStorage { template friend class QVarLengthArray; using Base = QVLABase; using Storage = QVLAStorage; static_assert(std::is_nothrow_destructible_v, "Types with throwing destructors are not supported in Qt containers."); using Base::verify; public: using size_type = typename Base::size_type; using value_type = typename Base::value_type; using pointer = typename Base::pointer; using const_pointer = typename Base::const_pointer; using reference = typename Base::reference; using const_reference = typename Base::const_reference; using difference_type = typename Base::difference_type; using iterator = typename Base::iterator; using const_iterator = typename Base::const_iterator; using reverse_iterator = typename Base::reverse_iterator; using const_reverse_iterator = typename Base::const_reverse_iterator; QVarLengthArray() noexcept { this->a = Prealloc; this->s = 0; this->ptr = this->array; } inline explicit QVarLengthArray(qsizetype size); QVarLengthArray(const QVarLengthArray &other) : QVarLengthArray{} { append(other.constData(), other.size()); } QVarLengthArray(QVarLengthArray &&other) noexcept(std::is_nothrow_move_constructible_v) : Base(other) { const auto otherInlineStorage = reinterpret_cast(other.array); if (data() == otherInlineStorage) { // inline buffer - move into our inline buffer: this->ptr = this->array; QtPrivate::q_uninitialized_relocate_n(otherInlineStorage, size(), data()); } else { // heap buffer - we just stole the memory } // reset other to internal storage: other.a = Prealloc; other.s = 0; other.ptr = otherInlineStorage; } QVarLengthArray(std::initializer_list args) : QVarLengthArray(args.begin(), args.end()) { } template = true> inline QVarLengthArray(InputIterator first, InputIterator last) : QVarLengthArray() { QtPrivate::reserveIfForwardIterator(this, first, last); std::copy(first, last, std::back_inserter(*this)); } inline ~QVarLengthArray() { if constexpr (QTypeInfo::isComplex) std::destroy_n(data(), size()); if (data() != reinterpret_cast(this->array)) free(data()); } inline QVarLengthArray &operator=(const QVarLengthArray &other) { if (this != &other) { clear(); append(other.constData(), other.size()); } return *this; } QVarLengthArray &operator=(QVarLengthArray &&other) noexcept(std::is_nothrow_move_constructible_v) { // we're only required to be self-move-assignment-safe // when we're in the moved-from state (Hinnant criterion) // the moved-from state is the empty state, so we're good with the clear() here: clear(); Q_ASSERT(capacity() >= Prealloc); const auto otherInlineStorage = other.array; if (other.ptr != otherInlineStorage) { // heap storage: steal the external buffer, reset other to otherInlineStorage this->a = std::exchange(other.a, Prealloc); this->ptr = std::exchange(other.ptr, otherInlineStorage); } else { // inline storage: move into our storage (doesn't matter whether inline or external) QtPrivate::q_uninitialized_relocate_n(other.data(), other.size(), data()); } this->s = std::exchange(other.s, 0); return *this; } QVarLengthArray &operator=(std::initializer_list list) { resize(qsizetype(list.size())); std::copy(list.begin(), list.end(), QT_MAKE_CHECKED_ARRAY_ITERATOR(begin(), size())); return *this; } inline void removeLast() { Base::pop_back(); } #ifdef Q_QDOC inline qsizetype size() const { return this->s; } #endif using Base::size; inline qsizetype count() const { return size(); } inline qsizetype length() const { return size(); } inline T &first() { return front(); } inline const T &first() const { return front(); } T &last() { return back(); } const T &last() const { return back(); } bool isEmpty() const { return empty(); } void resize(qsizetype sz) { Base::resize_impl(Prealloc, this->array, sz); } inline void clear() { resize(0); } void squeeze() { reallocate(size(), size()); } using Base::capacity; #ifdef Q_QDOC qsizetype capacity() const { return this->a; } #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) { verify(idx); return data()[idx]; } inline const T &operator[](qsizetype idx) const { verify(idx); return data()[idx]; } #endif 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) { if (size() == capacity()) emplace_back(T(t)); else emplace_back(t); } void append(T &&t) { emplace_back(std::move(t)); } void append(const T *buf, qsizetype sz) { Base::append_impl(Prealloc, this->array, buf, sz); } inline QVarLengthArray &operator<<(const T &t) { append(t); return *this; } inline QVarLengthArray &operator<<(T &&t) { append(std::move(t)); return *this; } inline QVarLengthArray &operator+=(const T &t) { append(t); return *this; } inline QVarLengthArray &operator+=(T &&t) { append(std::move(t)); return *this; } #if QT_DEPRECATED_SINCE(6, 3) QT_DEPRECATED_VERSION_X_6_3("This is slow. If you must, use insert(cbegin(), ~~~) instead.") void prepend(T &&t); QT_DEPRECATED_VERSION_X_6_3("This is slow. If you must, use insert(cbegin(), ~~~) instead.") void prepend(const T &t); #endif 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 qsizetype removeAll(const AT &t); template 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; } inline const T *data() const { return this->ptr; } #endif using Base::data; inline const T *constData() const { return data(); } #ifdef Q_QDOC inline iterator begin() { return data(); } inline const_iterator begin() const { return data(); } inline const_iterator cbegin() const { return begin(); } inline const_iterator constBegin() const { return begin(); } inline iterator end() { return data() + size(); } inline const_iterator end() const { return data() + size(); } inline const_iterator cend() const { return end(); } #endif using Base::begin; using Base::cbegin; auto constBegin() const -> const_iterator { return begin(); } using Base::end; using Base::cend; inline const_iterator constEnd() const { return end(); } #ifdef Q_QDOC reverse_iterator rbegin() { return reverse_iterator(end()); } reverse_iterator rend() { return reverse_iterator(begin()); } const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } const_reverse_iterator crbegin() const { return const_reverse_iterator(end()); } const_reverse_iterator crend() const { return const_reverse_iterator(begin()); } #endif using Base::rbegin; using Base::crbegin; using Base::rend; using Base::crend; iterator insert(const_iterator before, qsizetype n, const T &x) { return Base::insert_impl(Prealloc, this->array, before, n, 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 inline bool empty() const { return isEmpty(); } #endif using Base::empty; inline void push_back(const T &t) { append(t); } void push_back(T &&t) { append(std::move(t)); } #ifdef Q_QDOC inline void pop_back() { removeLast(); } inline T &front() { return first(); } inline const T &front() const { return first(); } inline T &back() { return last(); } inline const T &back() const { return last(); } #endif using Base::pop_back; using Base::front; using Base::back; void shrink_to_fit() { squeeze(); } template iterator emplace(const_iterator pos, Args &&...args) { return Base::emplace_impl(Prealloc, this->array, pos, std::forward(args)...); } template T &emplace_back(Args &&...args) { return Base::emplace_back_impl(Prealloc, this->array, std::forward(args)...); } #ifdef Q_QDOC template friend inline bool operator==(const QVarLengthArray &l, const QVarLengthArray &r); template friend inline bool operator!=(const QVarLengthArray &l, const QVarLengthArray &r); template friend inline bool operator< (const QVarLengthArray &l, const QVarLengthArray &r); template friend inline bool operator> (const QVarLengthArray &l, const QVarLengthArray &r); template friend inline bool operator<=(const QVarLengthArray &l, const QVarLengthArray &r); template friend inline bool operator>=(const QVarLengthArray &l, const QVarLengthArray &r); #else template friend QTypeTraits::compare_eq_result operator==(const QVarLengthArray &l, const QVarLengthArray &r) { return l.equal(r); } template friend QTypeTraits::compare_eq_result operator!=(const QVarLengthArray &l, const QVarLengthArray &r) { return !(l == r); } template friend QTypeTraits::compare_lt_result operator<(const QVarLengthArray &lhs, const QVarLengthArray &rhs) noexcept(noexcept(std::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()))) { return lhs.less_than(rhs); } template friend QTypeTraits::compare_lt_result operator>(const QVarLengthArray &lhs, const QVarLengthArray &rhs) noexcept(noexcept(lhs < rhs)) { return rhs < lhs; } template friend QTypeTraits::compare_lt_result operator<=(const QVarLengthArray &lhs, const QVarLengthArray &rhs) noexcept(noexcept(lhs < rhs)) { return !(lhs > rhs); } template friend QTypeTraits::compare_lt_result operator>=(const QVarLengthArray &lhs, const QVarLengthArray &rhs) noexcept(noexcept(lhs < rhs)) { return !(lhs < rhs); } #endif private: template bool equal(const QVarLengthArray &other) const { return Base::equal(other); } template bool less_than(const QVarLengthArray &other) const { return Base::less_than(other); } void reallocate(qsizetype sz, qsizetype alloc) { Base::reallocate_impl(Prealloc, this->array, sz, alloc); } using Base::isValidIterator; }; template ::value_type, QtPrivate::IfIsInputIterator = true> QVarLengthArray(InputIterator, InputIterator) -> QVarLengthArray; template Q_INLINE_TEMPLATE QVarLengthArray::QVarLengthArray(qsizetype asize) { this->s = asize; static_assert(Prealloc > 0, "QVarLengthArray Prealloc must be greater than 0."); Q_ASSERT_X(size() >= 0, "QVarLengthArray::QVarLengthArray()", "Size must be greater than or equal to 0."); if (size() > Prealloc) { this->ptr = malloc(size() * sizeof(T)); Q_CHECK_PTR(data()); this->a = size(); } else { this->ptr = this->array; this->a = Prealloc; } if constexpr (QTypeInfo::isComplex) { T *i = end(); while (i != begin()) new (--i) T; } } template template Q_INLINE_TEMPLATE qsizetype QVLABase::indexOf(const AT &t, qsizetype from) const { if (from < 0) from = qMax(from + size(), qsizetype(0)); if (from < size()) { const T *n = data() + from - 1; const T *e = end(); while (++n != e) if (*n == t) return n - data(); } return -1; } template template Q_INLINE_TEMPLATE qsizetype QVLABase::lastIndexOf(const AT &t, qsizetype from) const { if (from < 0) from += size(); else if (from >= size()) from = size() - 1; if (from >= 0) { const T *b = begin(); const T *n = b + from + 1; while (n != b) { if (*--n == t) return n - b; } } return -1; } template template Q_INLINE_TEMPLATE bool QVLABase::contains(const AT &t) const { const T *b = begin(); const T *i = end(); while (i != b) { if (*--i == t) return true; } return false; } template Q_OUTOFLINE_TEMPLATE void QVLABase::append_impl(qsizetype prealloc, void *array, const T *abuf, qsizetype increment) { Q_ASSERT(abuf || increment == 0); if (increment <= 0) return; const qsizetype asize = size() + increment; if (asize >= capacity()) reallocate_impl(prealloc, array, size(), qMax(size() * 2, asize)); if constexpr (QTypeInfo::isComplex) std::uninitialized_copy_n(abuf, increment, end()); else memcpy(static_cast(end()), static_cast(abuf), increment * sizeof(T)); this->s = asize; } template Q_OUTOFLINE_TEMPLATE void QVLABase::reallocate_impl(qsizetype prealloc, void *array, qsizetype asize, qsizetype aalloc) { Q_ASSERT(aalloc >= asize); Q_ASSERT(data()); T *oldPtr = data(); qsizetype osize = size(); const qsizetype copySize = qMin(asize, osize); Q_ASSUME(copySize >= 0); if (aalloc != capacity()) { struct free_deleter { void operator()(void *p) const noexcept { free(p); } }; std::unique_ptr guard; void *newPtr; qsizetype newA; if (aalloc > prealloc) { newPtr = malloc(aalloc * sizeof(T)); guard.reset(newPtr); Q_CHECK_PTR(newPtr); // could throw // by design: in case of QT_NO_EXCEPTIONS malloc must not fail or it crashes here newA = aalloc; } else { newPtr = array; newA = prealloc; } QtPrivate::q_uninitialized_relocate_n(oldPtr, copySize, reinterpret_cast(newPtr)); // commit: ptr = newPtr; guard.release(); a = newA; } s = copySize; // destroy remaining old objects if constexpr (QTypeInfo::isComplex) { if (osize > asize) std::destroy(oldPtr + asize, oldPtr + osize); } if (oldPtr != reinterpret_cast(array) && oldPtr != data()) free(oldPtr); if constexpr (QTypeInfo::isComplex) { // call default constructor for new objects (which can throw) while (size() < asize) { new (data() + size()) T; ++s; } } else { s = asize; } } 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 QVLABase::value(qsizetype i, const T &defaultValue) const { return (size_t(i) >= size_t(size())) ? defaultValue : operator[](i); } template inline void QVarLengthArray::insert(qsizetype i, T &&t) { verify(i, 0); insert(cbegin() + i, std::move(t)); } template inline void QVarLengthArray::insert(qsizetype i, const T &t) { verify(i, 0); insert(begin() + i, 1, t); } template inline void QVarLengthArray::insert(qsizetype i, qsizetype n, const T &t) { verify(i, 0); insert(begin() + i, n, t); } template inline void QVLABase::remove(qsizetype i, qsizetype n) { verify(i, n); erase(begin() + i, begin() + i + n); } template template inline qsizetype QVLABase::removeAll(const AT &t) { return QtPrivate::sequential_erase_with_copy(*this, t); } template template inline bool QVLABase::removeOne(const AT &t) { return QtPrivate::sequential_erase_one(*this, t); } template template inline qsizetype QVLABase::removeIf(Predicate pred) { return QtPrivate::sequential_erase_if(*this, pred); } #if QT_DEPRECATED_SINCE(6, 3) template inline void QVarLengthArray::prepend(T &&t) { insert(cbegin(), std::move(t)); } template inline void QVarLengthArray::prepend(const T &t) { insert(begin(), 1, t); } #endif template inline void QVLABase::replace(qsizetype i, const T &t) { verify(i); data()[i] = t; } template template Q_OUTOFLINE_TEMPLATE auto QVLABase::emplace_impl(qsizetype prealloc, void *array, const_iterator before, Args &&...args) -> iterator { Q_ASSERT_X(isValidIterator(before), "QVarLengthArray::insert", "The specified const_iterator argument 'before' is invalid"); Q_ASSERT(size() <= capacity()); Q_ASSERT(capacity() > 0); qsizetype offset = qsizetype(before - cbegin()); if (size() == capacity()) reallocate_impl(prealloc, array, size(), size() * 2); if constexpr (!QTypeInfo::isRelocatable) { T *b = begin() + offset; T *i = end(); T *j = i + 1; // The new end-element needs to be constructed, the rest must be move assigned if (i != b) { new (--j) T(std::move(*--i)); while (i != b) *--j = std::move(*--i); *b = T(std::forward(args)...); } else { new (b) T(std::forward(args)...); } } else { T *b = begin() + offset; memmove(static_cast(b + 1), static_cast(b), (size() - offset) * sizeof(T)); new (b) T(std::forward(args)...); } this->s += 1; return data() + offset; } template Q_OUTOFLINE_TEMPLATE auto QVLABase::insert_impl(qsizetype prealloc, void *array, const_iterator before, qsizetype n, const T &t) -> iterator { Q_ASSERT_X(isValidIterator(before), "QVarLengthArray::insert", "The specified const_iterator argument 'before' is invalid"); qsizetype offset = qsizetype(before - cbegin()); if (n != 0) { const T copy(t); // `t` could alias an element in [begin(), end()[ resize_impl(prealloc, array, size() + n); if constexpr (!QTypeInfo::isRelocatable) { T *b = begin() + offset; T *j = end(); T *i = j - n; while (i != b) *--j = *--i; i = b + n; while (i != b) *--i = copy; } else { T *b = begin() + offset; T *i = b + n; memmove(static_cast(i), static_cast(b), (size() - offset - n) * sizeof(T)); while (i != b) new (--i) T(copy); } } return data() + offset; } 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"); qsizetype f = qsizetype(abegin - cbegin()); qsizetype l = qsizetype(aend - cbegin()); qsizetype n = l - f; if (n == 0) // avoid UB in std::move() below return data() + f; Q_ASSERT(n > 0); // aend must be reachable from abegin if constexpr (QTypeInfo::isComplex) { std::move(begin() + l, end(), QT_MAKE_CHECKED_ARRAY_ITERATOR(begin() + f, size() - f)); std::destroy(end() - n, end()); } else { memmove(static_cast(data() + f), static_cast(data() + l), (size() - l) * sizeof(T)); } this->s -= n; return data() + f; } #ifdef Q_QDOC // Fake definitions for qdoc, only the redeclaration is used. template bool operator==(const QVarLengthArray &l, const QVarLengthArray &r) { return bool{}; } template bool operator!=(const QVarLengthArray &l, const QVarLengthArray &r) { return bool{}; } template bool operator< (const QVarLengthArray &l, const QVarLengthArray &r) { return bool{}; } template bool operator> (const QVarLengthArray &l, const QVarLengthArray &r) { return bool{}; } template bool operator<=(const QVarLengthArray &l, const QVarLengthArray &r) { return bool{}; } template bool operator>=(const QVarLengthArray &l, const QVarLengthArray &r) { return bool{}; } #endif template size_t qHash(const QVarLengthArray &key, size_t seed = 0) noexcept(QtPrivate::QNothrowHashable_v) { return key.hash(seed); } template qsizetype erase(QVarLengthArray &array, const AT &t) { return array.removeAll(t); } template qsizetype erase_if(QVarLengthArray &array, Predicate pred) { return array.removeIf(pred); } QT_END_NAMESPACE #endif // QVARLENGTHARRAY_H