1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
7 \brief The QVarLengthArray class provides a low-level variable-length array.
12 The C++ language doesn't support variable-length arrays on the stack.
13 For example, the following code won't compile:
15 \snippet code/doc_src_qvarlengtharray.cpp 0
17 The alternative is to allocate the array on the heap (with
20 \snippet code/doc_src_qvarlengtharray.cpp 1
22 However, if myfunc() is called very frequently from the
23 application's inner loop, heap allocation can be a major source
26 QVarLengthArray is an attempt to work around this gap in the C++
27 language. It allocates a certain number of elements on the stack,
28 and if you resize the array to a larger size, it automatically
29 uses the heap instead. Stack allocation has the advantage that
30 it is much faster than heap allocation.
33 \snippet code/doc_src_qvarlengtharray.cpp 2
35 In the example above, QVarLengthArray will preallocate 1024
36 elements on the stack and use them unless \c{n + 1} is greater
37 than 1024. If you omit the second template argument,
38 QVarLengthArray's default of 256 is used.
40 QVarLengthArray's value type must be an \l{assignable data type}.
41 This covers most data types that are commonly used, but the
42 compiler won't let you, for example, store a QWidget as a value;
43 instead, store a QWidget *.
45 QVarLengthArray, like QList, provides a resizable array data
46 structure. The main differences between the two classes are:
49 \li QVarLengthArray's API is much more low-level and it lacks
50 some of QList's functionality.
52 \li QVarLengthArray doesn't initialize the memory if the value is
53 a basic type. (QList always does.)
55 \li QList uses \l{implicit sharing} as a memory optimization.
56 QVarLengthArray doesn't provide that feature; however, it
57 usually produces slightly better performance due to reduced
58 overhead, especially in tight loops.
61 In summary, QVarLengthArray is a low-level optimization class
62 that only makes sense in very specific cases. It is used a few
63 places inside Qt and was added to Qt's public API for the
64 convenience of advanced users.
69/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::QVarLengthArray()
71 Constructs an array with an initial size of zero.
74/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::QVarLengthArray(qsizetype size)
76 Constructs an array with an initial size of \a size elements.
78 If the value type is a primitive type (e.g., char, int, float) or
79 a pointer type (e.g., QWidget *), the elements are not
80 initialized. For other types, the elements are initialized with a
81 \l{default-constructed value}.
85 \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::QVarLengthArray(qsizetype size, const T &v)
88 Constructs an array with an initial size of \a size elements filled with
91 \note This constructor is only available when \c T is copy-constructible.
97/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::QVarLengthArray(std::initializer_list<T> args)
100 Constructs an array from the std::initializer_list given by \a args.
102 This constructor is only enabled if the compiler supports C++11 initializer
106/*! \fn template<class T, qsizetype Prealloc> template<typename InputIterator, if_input_iterator<InputIterator>> QVarLengthArray<T, Prealloc>::QVarLengthArray(InputIterator first, InputIterator last)
109 Constructs an array with the contents in the iterator range [\a first, \a last).
111 This constructor only participates in overload resolution if
112 \c InputIterator meets the requirements of an
113 \l {https://en.cppreference.com/w/cpp/named_req/InputIterator} {LegacyInputIterator}.
115 The value type of \c InputIterator must be convertible to \c T.
119/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::~QVarLengthArray()
124/*! \fn template<class T, qsizetype Prealloc> qsizetype QVarLengthArray<T, Prealloc>::size() const
126 Returns the number of elements in the array.
128 \sa isEmpty(), resize()
131/*! \fn template<class T, qsizetype Prealloc> qsizetype QVarLengthArray<T, Prealloc>::count() const
135 \sa isEmpty(), resize()
138/*! \fn template<class T, qsizetype Prealloc> qsizetype QVarLengthArray<T, Prealloc>::length() const
143 \sa isEmpty(), resize()
146/*! \fn template<class T, qsizetype Prealloc> T& QVarLengthArray<T, Prealloc>::first()
148 Returns a reference to the first item in the array. The array must
149 not be empty. If the array can be empty, check isEmpty() before
150 calling this function.
152 \sa last(), isEmpty()
155/*! \fn template<class T, qsizetype Prealloc> const T& QVarLengthArray<T, Prealloc>::first() const
160/*! \fn template<class T, qsizetype Prealloc> T& QVarLengthArray<T, Prealloc>::front()
163 Same as first(). Provided for STL-compatibility.
166/*! \fn template<class T, qsizetype Prealloc> const T& QVarLengthArray<T, Prealloc>::front() const
172/*! \fn template<class T, qsizetype Prealloc> T& QVarLengthArray<T, Prealloc>::last()
174 Returns a reference to the last item in the array. The array must
175 not be empty. If the array can be empty, check isEmpty() before
176 calling this function.
178 \sa first(), isEmpty()
181/*! \fn template<class T, qsizetype Prealloc> const T& QVarLengthArray<T, Prealloc>::last() const
186/*! \fn template<class T, qsizetype Prealloc> T& QVarLengthArray<T, Prealloc>::back()
189 Same as last(). Provided for STL-compatibility.
192/*! \fn template<class T, qsizetype Prealloc> const T& QVarLengthArray<T, Prealloc>::back() const
198/*! \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::shrink_to_fit()
201 Same as squeeze(). Provided for STL-compatibility.
204/*! \fn template<class T, qsizetype Prealloc> bool QVarLengthArray<T, Prealloc>::isEmpty() const
206 Returns \c true if the array has size 0; otherwise returns \c false.
211/*! \fn template<class T, qsizetype Prealloc> bool QVarLengthArray<T, Prealloc>::empty() const
214 Returns \c true if the array has size 0; otherwise returns \c false.
216 Same as isEmpty(). Provided for STL-compatibility.
219/*! \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::clear()
221 Removes all the elements from the array.
226/*! \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::resize(qsizetype size)
228 Sets the size of the array to \a size. If \a size is greater than
229 the current size, elements are added to the end. If \a size is
230 less than the current size, elements are removed from the end.
232 If the value type is a primitive type (e.g., char, int, float) or
233 a pointer type (e.g., QWidget *), new elements are not
234 initialized. For other types, the elements are initialized with a
235 \l{default-constructed value}.
237 \sa size(), squeeze()
241 \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::resize(qsizetype size, const T &v)
244 Sets the size of the array to \a size. If \a size is greater than
245 the current size, copies of \a v are added to the end. If \a size is
246 less than the current size, elements are removed from the end.
248 \note This function is only available when \c T is copy-constructible.
250 \sa size(), squeeze()
253/*! \fn template<class T, qsizetype Prealloc> qsizetype QVarLengthArray<T, Prealloc>::capacity() const
255 Returns the maximum number of elements that can be stored in the
256 array without forcing a reallocation.
258 The sole purpose of this function is to provide a means of fine
259 tuning QVarLengthArray's memory usage. In general, you will rarely ever
260 need to call this function. If you want to know how many items are
261 in the array, call size().
263 \sa reserve(), squeeze()
266/*! \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::reserve(qsizetype size)
268 Attempts to allocate memory for at least \a size elements. If you
269 know in advance how large the array can get, you can call this
270 function and if you call resize() often, you are likely to get
271 better performance. If \a size is an underestimate, the worst
272 that will happen is that the QVarLengthArray will be a bit
275 The sole purpose of this function is to provide a means of fine
276 tuning QVarLengthArray's memory usage. In general, you will
277 rarely ever need to call this function. If you want to change the
278 size of the array, call resize().
280 \sa capacity(), squeeze()
283/*! \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::squeeze()
286 Releases any memory not required to store the items.
287 If the container can fit its storage on the stack allocation,
288 it will free the heap allocation and copy the elements back to the stack.
290 The sole purpose of this function is to provide a means of fine
291 tuning QVarLengthArray's memory usage. In general, you will rarely ever
292 need to call this function.
294 \sa reserve(), capacity(), resize()
297/*! \fn template<class T, qsizetype Prealloc> T &QVarLengthArray<T, Prealloc>::operator[](qsizetype i)
299 Returns a reference to the item at index position \a i.
301 \a i must be a valid index position in the array (i.e., 0 <= \a i
307/*! \fn template<class T, qsizetype Prealloc> const T &QVarLengthArray<T, Prealloc>::operator[](qsizetype i) const
314 \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::append(const T &t)
316 Appends item \a t to the array, extending the array if necessary.
322 \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::push_back(const T &t)
325 Appends item \a t to the array, extending the array if necessary.
326 Provided for STL-compatibility.
330 \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::append(T &&t)
334 \note Unlike the lvalue overload of append(), passing a reference to
335 an object that is already an element of \c *this leads to undefined
339 vla.append(std::move(vla[0])); // BUG: passing an object that is already in the container
344 \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::push_back(T &&t)
348 \note Unlike the lvalue overload of push_back(), passing a reference to
349 an object that is already an element of \c *this leads to undefined
353 vla.push_back(std::move(vla[0])); // BUG: passing an object that is already in the container
358 \fn template<class T, qsizetype Prealloc> inline void QVarLengthArray<T, Prealloc>::removeLast()
361 Decreases the size of the array by one. The allocated size is not changed.
367 \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::pop_back()
370 Same as removeLast(). Provided for STL-compatibility.
374 \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::append(const T *buf, qsizetype size)
376 Appends \a size amount of items referenced by \a buf to this array.
380/*! \fn template<class T, qsizetype Prealloc> T *QVarLengthArray<T, Prealloc>::data()
382 Returns a pointer to the data stored in the array. The pointer can
383 be used to access and modify the items in the array.
386 \snippet code/doc_src_qvarlengtharray.cpp 3
388 The pointer remains valid as long as the array isn't reallocated.
390 This function is mostly useful to pass an array to a function
391 that accepts a plain C++ array.
393 \sa constData(), operator[]()
396/*! \fn template<class T, qsizetype Prealloc> const T *QVarLengthArray<T, Prealloc>::data() const
401/*! \fn template<class T, qsizetype Prealloc> const T *QVarLengthArray<T, Prealloc>::constData() const
403 Returns a const pointer to the data stored in the array. The
404 pointer can be used to access the items in the array. The
405 pointer remains valid as long as the array isn't reallocated.
407 This function is mostly useful to pass an array to a function
408 that accepts a plain C++ array.
410 \sa data(), operator[]()
413/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc> &QVarLengthArray<T, Prealloc>::operator=(const QVarLengthArray<T, Prealloc> &other)
414 Assigns \a other to this array and returns a reference to this array.
417/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc> &QVarLengthArray<T, Prealloc>::operator=(QVarLengthArray<T, Prealloc> &&other)
418 Move-assigns \a other to this array and returns a reference to this array.
419 After the move, \a other is empty.
423/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc> &QVarLengthArray<T, Prealloc>::operator=(std::initializer_list<T> list)
426 Assigns the values of \a list to this array, and returns a reference to this array.
428 This constructor is only enabled if the compiler supports C++11 initializer
432/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::QVarLengthArray(const QVarLengthArray<T, Prealloc> &other)
433 Constructs a copy of \a other.
436/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::QVarLengthArray(QVarLengthArray<T, Prealloc> &&other)
437 Move-constructs this variable-length array from \a other. After the move, \a other is empty.
441/*! \fn template<class T, qsizetype Prealloc> const T &QVarLengthArray<T, Prealloc>::at(qsizetype i) const
443 Returns a reference to the item at index position \a i.
445 \a i must be a valid index position in the array (i.e., 0 <= \a i
448 \sa value(), operator[]()
451/*! \fn template<class T, qsizetype Prealloc> T QVarLengthArray<T, Prealloc>::value(qsizetype i) const
453 Returns the value at index position \a i.
455 If the index \a i is out of bounds, the function returns
456 a \l{default-constructed value}. If you are certain that
457 \a i is within bounds, you can use at() instead, which is slightly
460 \sa at(), operator[]()
463/*! \fn template<class T, qsizetype Prealloc> T QVarLengthArray<T, Prealloc>::value(qsizetype i, const T &defaultValue) const
467 If the index \a i is out of bounds, the function returns
472 \typedef QVarLengthArray::size_type
475 Typedef for int. Provided for STL compatibility.
479 \typedef QVarLengthArray::value_type
482 Typedef for T. Provided for STL compatibility.
486 \typedef QVarLengthArray::difference_type
489 Typedef for ptrdiff_t. Provided for STL compatibility.
493 \typedef QVarLengthArray::pointer
496 Typedef for T *. Provided for STL compatibility.
500 \typedef QVarLengthArray::const_pointer
503 Typedef for const T *. Provided for STL compatibility.
507 \typedef QVarLengthArray::reference
510 Typedef for T &. Provided for STL compatibility.
514 \typedef QVarLengthArray::const_reference
517 Typedef for const T &. Provided for STL compatibility.
521 \typedef QVarLengthArray::const_iterator
524 Typedef for const T *. Provided for STL compatibility.
528 \typedef QVarLengthArray::iterator
531 Typedef for T *. Provided for STL compatibility.
535 \typedef QVarLengthArray::const_reverse_iterator
538 Typedef for \c{std::reverse_iterator<const T*>}. Provided for STL compatibility.
542 \typedef QVarLengthArray::reverse_iterator
545 Typedef for \c{std::reverse_iterator<T*>}. Provided for STL compatibility.
549 \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::prepend(const T &value)
550 \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::prepend(T &&value)
553 \deprecated [6.3] This is slow. If you must, use \c{insert(cbegin(), ~~~)} instead.
555 Inserts \a value at the beginning of the array.
558 This is the same as vector.insert(0, \a value).
560 For large arrays, this operation can be slow (\l{linear time}),
561 because it requires moving all the items in the vector by one
562 position further in memory. If you want a container class that
563 provides a fast prepend() function, use std::list instead.
565 \sa append(), insert()
568/*! \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::replace(qsizetype i, const T &value)
571 Replaces the item at index position \a i with \a value.
573 \a i must be a valid index position in the array (i.e., 0 <= \a
576 \sa operator[](), remove()
579/*! \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::remove(qsizetype i, qsizetype count)
584 Removes \a count elements from the middle of the array, starting at
587 \sa insert(), replace()
590/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::iterator QVarLengthArray<T, Prealloc>::begin()
593 Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first item in
596 \sa constBegin(), end()
599/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::const_iterator QVarLengthArray<T, Prealloc>::begin() const
604/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::const_iterator QVarLengthArray<T, Prealloc>::cbegin() const
607 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item
613/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::const_iterator QVarLengthArray<T, Prealloc>::constBegin() const
616 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item
619 \sa begin(), constEnd()
622/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::iterator QVarLengthArray<T, Prealloc>::end()
625 Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item
626 after the last item in the array.
628 \sa begin(), constEnd()
631/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::const_iterator QVarLengthArray<T, Prealloc>::end() const
637/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::const_iterator QVarLengthArray<T, Prealloc>::cend() const
640 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary
641 item after the last item in the array.
646/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::const_iterator QVarLengthArray<T, Prealloc>::constEnd() const
649 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary
650 item after the last item in the array.
652 \sa constBegin(), end()
655/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::reverse_iterator QVarLengthArray<T, Prealloc>::rbegin()
658 Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to the first
659 item in the variable length array, in reverse order.
661 \sa begin(), crbegin(), rend()
664/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::const_reverse_iterator QVarLengthArray<T, Prealloc>::rbegin() const
669/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::const_reverse_iterator QVarLengthArray<T, Prealloc>::crbegin() const
672 Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing to the first
673 item in the variable length array, in reverse order.
675 \sa begin(), rbegin(), rend()
678/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::reverse_iterator QVarLengthArray<T, Prealloc>::rend()
681 Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to one past
682 the last item in the variable length array, in reverse order.
684 \sa end(), crend(), rbegin()
687/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::const_reverse_iterator QVarLengthArray<T, Prealloc>::rend() const
692/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::const_reverse_iterator QVarLengthArray<T, Prealloc>::crend() const
695 Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing to one
696 past the last item in the variable length array, in reverse order.
698 \sa end(), rend(), rbegin()
701/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::iterator QVarLengthArray<T, Prealloc>::erase(const_iterator pos)
704 Removes the item pointed to by the iterator \a pos from the
705 vector, and returns an iterator to the next item in the vector
706 (which may be end()).
708 \sa insert(), remove()
711/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::iterator QVarLengthArray<T, Prealloc>::erase(const_iterator begin, const_iterator end)
716 Removes all the items from \a begin up to (but not including) \a
717 end. Returns an iterator to the same item that \a end referred to
722 \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::insert(qsizetype i, const T &value)
723 \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::insert(qsizetype i, T &&value)
726 Inserts \a value at index position \a i in the array. If \a i is
727 0, the value is prepended to the vector. If \a i is size(), the
728 value is appended to the vector.
730 For large arrays, this operation can be slow (\l{linear time}),
731 because it requires moving all the items at indexes \a i and
732 above by one position further in memory. If you want a container
733 class that provides a fast insert() function, use std::list
739/*! \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::insert(qsizetype i, qsizetype count, const T &value)
744 Inserts \a count copies of \a value at index position \a i in the
748/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::iterator QVarLengthArray<T, Prealloc>::insert(const_iterator before, const T &value)
749 \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::iterator QVarLengthArray<T, Prealloc>::insert(const_iterator before, T &&value)
754 Inserts \a value in front of the item pointed to by the iterator
755 \a before. Returns an iterator pointing at the inserted item.
759 \fn template <class T, qsizetype Prealloc> template <typename...Args> QVarLengthArray<T, Prealloc>::iterator QVarLengthArray<T, Prealloc>::emplace(const_iterator pos, Args &&...args)
763 Inserts an item in front of the item pointed to by the iterator
764 \a pos, passing \a args to its constructor.
766 Returns an iterator pointing at the emplaced item.
770 \fn template <class T, qsizetype Prealloc> template <typename...Args> T &QVarLengthArray<T, Prealloc>::emplace_back(Args &&...args)
773 Inserts an item at the back of this QVarLengthArray, passing
774 \a args to its constructor.
776 Returns a reference to the emplaced item.
779/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::iterator QVarLengthArray<T, Prealloc>::insert(const_iterator before, qsizetype count, const T &value)
782 Inserts \a count copies of \a value in front of the item pointed to
783 by the iterator \a before. Returns an iterator pointing at the
784 first of the inserted items.
789/*! \fn template<class T, qsizetype Prealloc1, qsizetype Prealloc2> bool operator==(const QVarLengthArray<T, Prealloc1> &left, const QVarLengthArray<T, Prealloc2> &right)
791 \relates QVarLengthArray
793 Returns \c true if the two arrays, specified by \a left and \a right, are equal.
795 Two arrays are considered equal if they contain the same values
798 This function requires the value type to have an implementation
801 \sa {operator!=(const QVarLengthArray<T, Prealloc1> &left, const QVarLengthArray<T, Prealloc2> &right)}{operator!=()}
804/*! \fn template<typename T, qsizetype Prealloc1, qsizetype Prealloc2> bool operator!=(const QVarLengthArray<T, Prealloc1> &left, const QVarLengthArray<T, Prealloc2> &right)
806 \relates QVarLengthArray
808 Returns \c true if the two arrays, specified by \a left and \a right, are \e not equal.
810 Two arrays are considered equal if they contain the same values
813 This function requires the value type to have an implementation
816 \sa {operator==(const QVarLengthArray<T, Prealloc1> &left, const QVarLengthArray<T, Prealloc2> &right)}{operator==()}
819/*! \fn template<typename T, qsizetype Prealloc1, qsizetype Prealloc2> bool operator<(const QVarLengthArray<T,Prealloc1> &lhs, const QVarLengthArray<T,Prealloc2> &rhs)
821 \relates QVarLengthArray
823 Returns \c true if variable length array \a lhs is
824 \l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare}
825 {lexicographically less than} \a rhs; otherwise returns \c false.
827 This function requires the value type to have an implementation
831/*! \fn template<typename T, qsizetype Prealloc1, qsizetype Prealloc2> bool operator<=(const QVarLengthArray<T,Prealloc1> &lhs, const QVarLengthArray<T,Prealloc2> &rhs)
833 \relates QVarLengthArray
835 Returns \c true if variable length array \a lhs is
836 \l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare}
837 {lexicographically less than or equal to} \a rhs; otherwise returns \c false.
839 This function requires the value type to have an implementation
843/*! \fn template<typename T, qsizetype Prealloc1, qsizetype Prealloc2> bool operator>(const QVarLengthArray<T,Prealloc1> &lhs, const QVarLengthArray<T,Prealloc2> &rhs)
845 \relates QVarLengthArray
847 Returns \c true if variable length array \a lhs is
848 \l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare}
849 {lexicographically greater than} \a rhs; otherwise returns \c false.
851 This function requires the value type to have an implementation
855/*! \fn template<typename T, qsizetype Prealloc1, qsizetype Prealloc2> bool operator>=(const QVarLengthArray<T,Prealloc1> &lhs, const QVarLengthArray<T,Prealloc2> &rhs)
857 \relates QVarLengthArray
859 Returns \c true if variable length array \a lhs is
860 \l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare}
861 {lexicographically greater than or equal to} \a rhs; otherwise returns \c false.
863 This function requires the value type to have an implementation
867/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc> &QVarLengthArray<T, Prealloc>::operator<<(const T &value)
870 Appends \a value to the array and returns a reference to this
873 \sa append(), operator+=()
876/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc> &QVarLengthArray<T, Prealloc>::operator<<(T &&value)
881 \sa append(), operator+=()
884/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc> &QVarLengthArray<T, Prealloc>::operator+=(const T &value)
887 Appends \a value to the array and returns a reference to this vector.
889 \sa append(), operator<<()
892/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc> &QVarLengthArray<T, Prealloc>::operator+=(T &&value)
897 \sa append(), operator<<()
900/*! \fn template<class T, qsizetype Prealloc> template <typename AT = T> qsizetype QVarLengthArray<T, Prealloc>::indexOf(const AT &value, qsizetype from = 0) const
903 Returns the index position of the first occurrence of \a value in
904 the array, searching forward from index position \a from.
905 Returns -1 if no item matched.
907 This function requires the value type to have an implementation of
910 \sa lastIndexOf(), contains()
913/*! \fn template<class T, qsizetype Prealloc> template <typename AT = T> qsizetype QVarLengthArray<T, Prealloc>::lastIndexOf(const AT &value, qsizetype from = -1) const
916 Returns the index position of the last occurrence of the value \a
917 value in the array, searching backward from index position \a
918 from. If \a from is -1 (the default), the search starts at the
919 last item. Returns -1 if no item matched.
921 This function requires the value type to have an implementation of
924 \sa indexOf(), contains()
927/*! \fn template<class T, qsizetype Prealloc> template <typename AT = T> bool QVarLengthArray<T, Prealloc>::contains(const AT &value) const
930 Returns \c true if the array contains an occurrence of \a value;
931 otherwise returns \c false.
933 This function requires the value type to have an implementation of
936 \sa indexOf(), lastIndexOf()
940 \fn template <typename T, qsizetype Prealloc> size_t qHash(const QVarLengthArray<T, Prealloc> &key, size_t seed = 0)
941 \relates QVarLengthArray
944 Returns the hash value for \a key, using \a seed to seed the
948/*! \fn template <typename T, qsizetype Prealloc> template <typename AT = T> qsizetype QVarLengthArray<T, Prealloc>::removeAll(const AT &t)
951 Removes all elements that compare equal to \a t from the
952 array. Returns the number of elements removed, if any.
957/*! \fn template <typename T, qsizetype Prealloc> template <typename AT = T> bool QVarLengthArray<T, Prealloc>::removeOne(const AT &t)
960 Removes the first element that compares equal to \a t from the
961 array. Returns whether an element was, in fact, removed.
966/*! \fn template <typename T, qsizetype Prealloc> template <typename Predicate> qsizetype QVarLengthArray<T, Prealloc>::removeIf(Predicate pred)
969 Removes all elements for which the predicate \a pred returns true
970 from the array. Returns the number of elements removed, if any.
975/*! \fn template <typename T, qsizetype Prealloc, typename AT> qsizetype erase(QVarLengthArray<T, Prealloc> &array, const AT &t)
976 \relates QVarLengthArray
979 Removes all elements that compare equal to \a t from the
980 array \a array. Returns the number of elements removed, if any.
982 \note \a t is not allowed to be a reference to an element inside \a
983 array. If you cannot be sure that this is not the case, take a copy
984 of \a t and call this function with the copy.
989/*! \fn template <typename T, qsizetype Prealloc, typename Predicate> qsizetype erase_if(QVarLengthArray<T, Prealloc> &array, Predicate pred)
990 \relates QVarLengthArray
993 Removes all elements for which the predicate \a pred returns true
994 from the list \a array. Returns the number of elements removed, if
1000/*! \fn template <class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::assign(qsizetype n, const T &t)
1003 Replaces the contents of this container with \a n copies of \a t.
1005 The size of this container will be equal to \a n. This function will only
1006 allocate memory if \a n exceeds the capacity of the container.
1009/*! \fn template <class T, qsizetype Prealloc> template <typename InputIterator, if_input_iterator<InputIterator>> QVarLengthArray<T, Prealloc>::assign(InputIterator first, InputIterator last)
1012 Replaces the contents of this container with a copy of the elements in the
1013 iterator range [\a first, \a last).
1015 The size of this container will be equal to the number of elements in the
1016 range [\a first, \a last). This function will only allocate memory if the
1017 number of elements in the range exceeds the capacity of the container.
1019 This function overload only participates in overload resolution if
1020 \c InputIterator meets the requirements of an
1021 \l {https://en.cppreference.com/w/cpp/named_req/InputIterator} {LegacyInputIterator}.
1023 The behavior is undefined if either argument is an iterator into *this.
1026/*! \fn template <class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::assign(std::initializer_list<T> list)
1029 Replaces the contents of this container with a copy of the elements of \a list.
1031 The size of this container will be equal to the number of elements in \a list.
1033 This function only allocates memory if the number of elements in \a list
1034 exceeds the capacity of the container.