Qt 6.x
The Qt SDK
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
qvarlengtharray.qdoc
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5 \class QVarLengthArray
6 \inmodule QtCore
7 \brief The QVarLengthArray class provides a low-level variable-length array.
8
9 \ingroup tools
10 \reentrant
11
12 The C++ language doesn't support variable-length arrays on the stack.
13 For example, the following code won't compile:
14
15 \snippet code/doc_src_qvarlengtharray.cpp 0
16
17 The alternative is to allocate the array on the heap (with
18 \c{new}):
19
20 \snippet code/doc_src_qvarlengtharray.cpp 1
21
22 However, if myfunc() is called very frequently from the
23 application's inner loop, heap allocation can be a major source
24 of slowdown.
25
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.
31
32 Example:
33 \snippet code/doc_src_qvarlengtharray.cpp 2
34
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.
39
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 *.
44
45 QVarLengthArray, like QList, provides a resizable array data
46 structure. The main differences between the two classes are:
47
48 \list
49 \li QVarLengthArray's API is much more low-level and it lacks
50 some of QList's functionality.
51
52 \li QVarLengthArray doesn't initialize the memory if the value is
53 a basic type. (QList always does.)
54
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.
59 \endlist
60
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.
65
66 \sa QList
67*/
68
69/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::QVarLengthArray()
70
71 Constructs an array with an initial size of zero.
72*/
73
74/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::QVarLengthArray(qsizetype size)
75
76 Constructs an array with an initial size of \a size elements.
77
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}.
82*/
83
84/*!
85 \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::QVarLengthArray(qsizetype size, const T &v)
86 \since 6.4
87
88 Constructs an array with an initial size of \a size elements filled with
89 copies of \a v.
90
91 \note This constructor is only available when \c T is copy-constructible.
92
93 \sa size(), squeeze()
94*/
95
96
97/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::QVarLengthArray(std::initializer_list<T> args)
98 \since 5.5
99
100 Constructs an array from the std::initializer_list given by \a args.
101
102 This constructor is only enabled if the compiler supports C++11 initializer
103 lists.
104*/
105
106/*! \fn template<class T, qsizetype Prealloc> template<typename InputIterator, if_input_iterator<InputIterator>> QVarLengthArray<T, Prealloc>::QVarLengthArray(InputIterator first, InputIterator last)
107 \since 5.14
108
109 Constructs an array with the contents in the iterator range [\a first, \a last).
110
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}.
114
115 The value type of \c InputIterator must be convertible to \c T.
116*/
117
118
119/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::~QVarLengthArray()
120
121 Destroys the array.
122*/
123
124/*! \fn template<class T, qsizetype Prealloc> qsizetype QVarLengthArray<T, Prealloc>::size() const
125
126 Returns the number of elements in the array.
127
128 \sa isEmpty(), resize()
129*/
130
131/*! \fn template<class T, qsizetype Prealloc> qsizetype QVarLengthArray<T, Prealloc>::count() const
132
133 Same as size().
134
135 \sa isEmpty(), resize()
136*/
137
138/*! \fn template<class T, qsizetype Prealloc> qsizetype QVarLengthArray<T, Prealloc>::length() const
139 \since 5.0
140
141 Same as size().
142
143 \sa isEmpty(), resize()
144*/
145
146/*! \fn template<class T, qsizetype Prealloc> T& QVarLengthArray<T, Prealloc>::first()
147
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.
151
152 \sa last(), isEmpty()
153*/
154
155/*! \fn template<class T, qsizetype Prealloc> const T& QVarLengthArray<T, Prealloc>::first() const
156
157 \overload
158*/
159
160/*! \fn template<class T, qsizetype Prealloc> T& QVarLengthArray<T, Prealloc>::front()
161 \since 5.0
162
163 Same as first(). Provided for STL-compatibility.
164*/
165
166/*! \fn template<class T, qsizetype Prealloc> const T& QVarLengthArray<T, Prealloc>::front() const
167 \since 5.0
168
169 \overload
170*/
171
172/*! \fn template<class T, qsizetype Prealloc> T& QVarLengthArray<T, Prealloc>::last()
173
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.
177
178 \sa first(), isEmpty()
179*/
180
181/*! \fn template<class T, qsizetype Prealloc> const T& QVarLengthArray<T, Prealloc>::last() const
182
183 \overload
184*/
185
186/*! \fn template<class T, qsizetype Prealloc> T& QVarLengthArray<T, Prealloc>::back()
187 \since 5.0
188
189 Same as last(). Provided for STL-compatibility.
190*/
191
192/*! \fn template<class T, qsizetype Prealloc> const T& QVarLengthArray<T, Prealloc>::back() const
193 \since 5.0
194
195 \overload
196*/
197
198/*! \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::shrink_to_fit()
199 \since 5.10
200
201 Same as squeeze(). Provided for STL-compatibility.
202*/
203
204/*! \fn template<class T, qsizetype Prealloc> bool QVarLengthArray<T, Prealloc>::isEmpty() const
205
206 Returns \c true if the array has size 0; otherwise returns \c false.
207
208 \sa size(), resize()
209*/
210
211/*! \fn template<class T, qsizetype Prealloc> bool QVarLengthArray<T, Prealloc>::empty() const
212 \since 5.0
213
214 Returns \c true if the array has size 0; otherwise returns \c false.
215
216 Same as isEmpty(). Provided for STL-compatibility.
217*/
218
219/*! \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::clear()
220
221 Removes all the elements from the array.
222
223 Same as resize(0).
224*/
225
226/*! \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::resize(qsizetype size)
227
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.
231
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}.
236
237 \sa size(), squeeze()
238*/
239
240/*!
241 \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::resize(qsizetype size, const T &v)
242 \since 6.4
243
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.
247
248 \note This function is only available when \c T is copy-constructible.
249
250 \sa size(), squeeze()
251*/
252
253/*! \fn template<class T, qsizetype Prealloc> qsizetype QVarLengthArray<T, Prealloc>::capacity() const
254
255 Returns the maximum number of elements that can be stored in the
256 array without forcing a reallocation.
257
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().
262
263 \sa reserve(), squeeze()
264*/
265
266/*! \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::reserve(qsizetype size)
267
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
273 slower.
274
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().
279
280 \sa capacity(), squeeze()
281*/
282
283/*! \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::squeeze()
284 \since 5.1
285
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.
289
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.
293
294 \sa reserve(), capacity(), resize()
295*/
296
297/*! \fn template<class T, qsizetype Prealloc> T &QVarLengthArray<T, Prealloc>::operator[](qsizetype i)
298
299 Returns a reference to the item at index position \a i.
300
301 \a i must be a valid index position in the array (i.e., 0 <= \a i
302 < size()).
303
304 \sa data(), at()
305*/
306
307/*! \fn template<class T, qsizetype Prealloc> const T &QVarLengthArray<T, Prealloc>::operator[](qsizetype i) const
308
309 \overload
310*/
311
312
313/*!
314 \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::append(const T &t)
315
316 Appends item \a t to the array, extending the array if necessary.
317
318 \sa removeLast()
319*/
320
321/*!
322 \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::push_back(const T &t)
323 \since 5.0
324
325 Appends item \a t to the array, extending the array if necessary.
326 Provided for STL-compatibility.
327*/
328
329/*!
330 \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::append(T &&t)
331 \overload append
332 \since 5.9
333
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
336 behavior:
337
338 \code
339 vla.append(std::move(vla[0])); // BUG: passing an object that is already in the container
340 \endcode
341*/
342
343/*!
344 \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::push_back(T &&t)
345 \overload push_back
346 \since 5.9
347
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
350 behavior:
351
352 \code
353 vla.push_back(std::move(vla[0])); // BUG: passing an object that is already in the container
354 \endcode
355*/
356
357/*!
358 \fn template<class T, qsizetype Prealloc> inline void QVarLengthArray<T, Prealloc>::removeLast()
359 \since 4.5
360
361 Decreases the size of the array by one. The allocated size is not changed.
362
363 \sa append()
364*/
365
366/*!
367 \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::pop_back()
368 \since 5.0
369
370 Same as removeLast(). Provided for STL-compatibility.
371*/
372
373/*!
374 \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::append(const T *buf, qsizetype size)
375
376 Appends \a size amount of items referenced by \a buf to this array.
377*/
378
379
380/*! \fn template<class T, qsizetype Prealloc> T *QVarLengthArray<T, Prealloc>::data()
381
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.
384
385 Example:
386 \snippet code/doc_src_qvarlengtharray.cpp 3
387
388 The pointer remains valid as long as the array isn't reallocated.
389
390 This function is mostly useful to pass an array to a function
391 that accepts a plain C++ array.
392
393 \sa constData(), operator[]()
394*/
395
396/*! \fn template<class T, qsizetype Prealloc> const T *QVarLengthArray<T, Prealloc>::data() const
397
398 \overload
399*/
400
401/*! \fn template<class T, qsizetype Prealloc> const T *QVarLengthArray<T, Prealloc>::constData() const
402
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.
406
407 This function is mostly useful to pass an array to a function
408 that accepts a plain C++ array.
409
410 \sa data(), operator[]()
411*/
412
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.
415 */
416
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.
420 \since 6.0
421 */
422
423/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc> &QVarLengthArray<T, Prealloc>::operator=(std::initializer_list<T> list)
424 \since 5.5
425
426 Assigns the values of \a list to this array, and returns a reference to this array.
427
428 This constructor is only enabled if the compiler supports C++11 initializer
429 lists.
430*/
431
432/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::QVarLengthArray(const QVarLengthArray<T, Prealloc> &other)
433 Constructs a copy of \a other.
434 */
435
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.
438 \since 6.0
439 */
440
441/*! \fn template<class T, qsizetype Prealloc> const T &QVarLengthArray<T, Prealloc>::at(qsizetype i) const
442
443 Returns a reference to the item at index position \a i.
444
445 \a i must be a valid index position in the array (i.e., 0 <= \a i
446 < size()).
447
448 \sa value(), operator[]()
449*/
450
451/*! \fn template<class T, qsizetype Prealloc> T QVarLengthArray<T, Prealloc>::value(qsizetype i) const
452
453 Returns the value at index position \a i.
454
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
458 faster.
459
460 \sa at(), operator[]()
461*/
462
463/*! \fn template<class T, qsizetype Prealloc> T QVarLengthArray<T, Prealloc>::value(qsizetype i, const T &defaultValue) const
464
465 \overload
466
467 If the index \a i is out of bounds, the function returns
468 \a defaultValue.
469*/
470
471/*!
472 \typedef QVarLengthArray::size_type
473 \since 4.7
474
475 Typedef for int. Provided for STL compatibility.
476*/
477
478/*!
479 \typedef QVarLengthArray::value_type
480 \since 4.7
481
482 Typedef for T. Provided for STL compatibility.
483*/
484
485/*!
486 \typedef QVarLengthArray::difference_type
487 \since 4.7
488
489 Typedef for ptrdiff_t. Provided for STL compatibility.
490*/
491
492/*!
493 \typedef QVarLengthArray::pointer
494 \since 4.7
495
496 Typedef for T *. Provided for STL compatibility.
497*/
498
499/*!
500 \typedef QVarLengthArray::const_pointer
501 \since 4.7
502
503 Typedef for const T *. Provided for STL compatibility.
504*/
505
506/*!
507 \typedef QVarLengthArray::reference
508 \since 4.7
509
510 Typedef for T &. Provided for STL compatibility.
511*/
512
513/*!
514 \typedef QVarLengthArray::const_reference
515 \since 4.7
516
517 Typedef for const T &. Provided for STL compatibility.
518*/
519
520/*!
521 \typedef QVarLengthArray::const_iterator
522 \since 4.7
523
524 Typedef for const T *. Provided for STL compatibility.
525*/
526
527/*!
528 \typedef QVarLengthArray::iterator
529 \since 4.7
530
531 Typedef for T *. Provided for STL compatibility.
532*/
533
534/*!
535 \typedef QVarLengthArray::const_reverse_iterator
536 \since 5.6
537
538 Typedef for \c{std::reverse_iterator<const T*>}. Provided for STL compatibility.
539*/
540
541/*!
542 \typedef QVarLengthArray::reverse_iterator
543 \since 5.6
544
545 Typedef for \c{std::reverse_iterator<T*>}. Provided for STL compatibility.
546*/
547
548/*!
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)
551
552 \since 4.8
553 \deprecated [6.3] This is slow. If you must, use \c{insert(cbegin(), ~~~)} instead.
554
555 Inserts \a value at the beginning of the array.
556
557
558 This is the same as vector.insert(0, \a value).
559
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.
564
565 \sa append(), insert()
566*/
567
568/*! \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::replace(qsizetype i, const T &value)
569
570 \since 4.8
571 Replaces the item at index position \a i with \a value.
572
573 \a i must be a valid index position in the array (i.e., 0 <= \a
574 i < size()).
575
576 \sa operator[](), remove()
577*/
578
579/*! \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::remove(qsizetype i, qsizetype count)
580
581 \overload
582 \since 4.8
583
584 Removes \a count elements from the middle of the array, starting at
585 index position \a i.
586
587 \sa insert(), replace()
588*/
589
590/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::iterator QVarLengthArray<T, Prealloc>::begin()
591 \since 4.8
592
593 Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first item in
594 the array.
595
596 \sa constBegin(), end()
597*/
598
599/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::const_iterator QVarLengthArray<T, Prealloc>::begin() const
600 \since 4.8
601 \overload
602*/
603
604/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::const_iterator QVarLengthArray<T, Prealloc>::cbegin() const
605 \since 5.0
606
607 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item
608 in the array.
609
610 \sa begin(), cend()
611*/
612
613/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::const_iterator QVarLengthArray<T, Prealloc>::constBegin() const
614 \since 4.8
615
616 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item
617 in the array.
618
619 \sa begin(), constEnd()
620*/
621
622/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::iterator QVarLengthArray<T, Prealloc>::end()
623 \since 4.8
624
625 Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item
626 after the last item in the array.
627
628 \sa begin(), constEnd()
629*/
630
631/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::const_iterator QVarLengthArray<T, Prealloc>::end() const
632 \since 4.8
633
634 \overload
635*/
636
637/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::const_iterator QVarLengthArray<T, Prealloc>::cend() const
638 \since 5.0
639
640 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary
641 item after the last item in the array.
642
643 \sa cbegin(), end()
644*/
645
646/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::const_iterator QVarLengthArray<T, Prealloc>::constEnd() const
647 \since 4.8
648
649 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary
650 item after the last item in the array.
651
652 \sa constBegin(), end()
653*/
654
655/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::reverse_iterator QVarLengthArray<T, Prealloc>::rbegin()
656 \since 5.6
657
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.
660
661 \sa begin(), crbegin(), rend()
662*/
663
664/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::const_reverse_iterator QVarLengthArray<T, Prealloc>::rbegin() const
665 \since 5.6
666 \overload
667*/
668
669/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::const_reverse_iterator QVarLengthArray<T, Prealloc>::crbegin() const
670 \since 5.6
671
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.
674
675 \sa begin(), rbegin(), rend()
676*/
677
678/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::reverse_iterator QVarLengthArray<T, Prealloc>::rend()
679 \since 5.6
680
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.
683
684 \sa end(), crend(), rbegin()
685*/
686
687/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::const_reverse_iterator QVarLengthArray<T, Prealloc>::rend() const
688 \since 5.6
689 \overload
690*/
691
692/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::const_reverse_iterator QVarLengthArray<T, Prealloc>::crend() const
693 \since 5.6
694
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.
697
698 \sa end(), rend(), rbegin()
699*/
700
701/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::iterator QVarLengthArray<T, Prealloc>::erase(const_iterator pos)
702 \since 4.8
703
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()).
707
708 \sa insert(), remove()
709*/
710
711/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::iterator QVarLengthArray<T, Prealloc>::erase(const_iterator begin, const_iterator end)
712
713 \overload
714 \since 4.8
715
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
718 before the call.
719*/
720
721/*!
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)
724 \since 4.8
725
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.
729
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
734 instead.
735
736 \sa remove()
737*/
738
739/*! \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::insert(qsizetype i, qsizetype count, const T &value)
740
741 \overload
742 \since 4.8
743
744 Inserts \a count copies of \a value at index position \a i in the
745 vector.
746*/
747
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)
750
751 \overload
752 \since 4.8
753
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.
756*/
757
758/*!
759 \fn template <class T, qsizetype Prealloc> template <typename...Args> QVarLengthArray<T, Prealloc>::iterator QVarLengthArray<T, Prealloc>::emplace(const_iterator pos, Args &&...args)
760
761 \since 6.3
762
763 Inserts an item in front of the item pointed to by the iterator
764 \a pos, passing \a args to its constructor.
765
766 Returns an iterator pointing at the emplaced item.
767*/
768
769/*!
770 \fn template <class T, qsizetype Prealloc> template <typename...Args> T &QVarLengthArray<T, Prealloc>::emplace_back(Args &&...args)
771 \since 6.3
772
773 Inserts an item at the back of this QVarLengthArray, passing
774 \a args to its constructor.
775
776 Returns a reference to the emplaced item.
777*/
778
779/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::iterator QVarLengthArray<T, Prealloc>::insert(const_iterator before, qsizetype count, const T &value)
780
781 \since 4.8
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.
785*/
786
787
788
789/*! \fn template<class T, qsizetype Prealloc1, qsizetype Prealloc2> bool operator==(const QVarLengthArray<T, Prealloc1> &left, const QVarLengthArray<T, Prealloc2> &right)
790
791 \relates QVarLengthArray
792 \since 4.8
793 Returns \c true if the two arrays, specified by \a left and \a right, are equal.
794
795 Two arrays are considered equal if they contain the same values
796 in the same order.
797
798 This function requires the value type to have an implementation
799 of \c operator==().
800
801 \sa {operator!=(const QVarLengthArray<T, Prealloc1> &left, const QVarLengthArray<T, Prealloc2> &right)}{operator!=()}
802*/
803
804/*! \fn template<typename T, qsizetype Prealloc1, qsizetype Prealloc2> bool operator!=(const QVarLengthArray<T, Prealloc1> &left, const QVarLengthArray<T, Prealloc2> &right)
805
806 \relates QVarLengthArray
807 \since 4.8
808 Returns \c true if the two arrays, specified by \a left and \a right, are \e not equal.
809
810 Two arrays are considered equal if they contain the same values
811 in the same order.
812
813 This function requires the value type to have an implementation
814 of \c operator==().
815
816 \sa {operator==(const QVarLengthArray<T, Prealloc1> &left, const QVarLengthArray<T, Prealloc2> &right)}{operator==()}
817*/
818
819/*! \fn template<typename T, qsizetype Prealloc1, qsizetype Prealloc2> bool operator<(const QVarLengthArray<T,Prealloc1> &lhs, const QVarLengthArray<T,Prealloc2> &rhs)
820 \since 5.6
821 \relates QVarLengthArray
822
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.
826
827 This function requires the value type to have an implementation
828 of \c operator<().
829*/
830
831/*! \fn template<typename T, qsizetype Prealloc1, qsizetype Prealloc2> bool operator<=(const QVarLengthArray<T,Prealloc1> &lhs, const QVarLengthArray<T,Prealloc2> &rhs)
832 \since 5.6
833 \relates QVarLengthArray
834
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.
838
839 This function requires the value type to have an implementation
840 of \c operator<().
841*/
842
843/*! \fn template<typename T, qsizetype Prealloc1, qsizetype Prealloc2> bool operator>(const QVarLengthArray<T,Prealloc1> &lhs, const QVarLengthArray<T,Prealloc2> &rhs)
844 \since 5.6
845 \relates QVarLengthArray
846
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.
850
851 This function requires the value type to have an implementation
852 of \c operator<().
853*/
854
855/*! \fn template<typename T, qsizetype Prealloc1, qsizetype Prealloc2> bool operator>=(const QVarLengthArray<T,Prealloc1> &lhs, const QVarLengthArray<T,Prealloc2> &rhs)
856 \since 5.6
857 \relates QVarLengthArray
858
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.
862
863 This function requires the value type to have an implementation
864 of \c operator<().
865*/
866
867/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc> &QVarLengthArray<T, Prealloc>::operator<<(const T &value)
868
869 \since 4.8
870 Appends \a value to the array and returns a reference to this
871 vector.
872
873 \sa append(), operator+=()
874*/
875
876/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc> &QVarLengthArray<T, Prealloc>::operator<<(T &&value)
877 \since 5.11
878
879 \overload
880
881 \sa append(), operator+=()
882*/
883
884/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc> &QVarLengthArray<T, Prealloc>::operator+=(const T &value)
885
886 \since 4.8
887 Appends \a value to the array and returns a reference to this vector.
888
889 \sa append(), operator<<()
890*/
891
892/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc> &QVarLengthArray<T, Prealloc>::operator+=(T &&value)
893 \since 5.11
894
895 \overload
896
897 \sa append(), operator<<()
898*/
899
900/*! \fn template<class T, qsizetype Prealloc> template <typename AT = T> qsizetype QVarLengthArray<T, Prealloc>::indexOf(const AT &value, qsizetype from = 0) const
901
902 \since 5.3
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.
906
907 This function requires the value type to have an implementation of
908 \c operator==().
909
910 \sa lastIndexOf(), contains()
911*/
912
913/*! \fn template<class T, qsizetype Prealloc> template <typename AT = T> qsizetype QVarLengthArray<T, Prealloc>::lastIndexOf(const AT &value, qsizetype from = -1) const
914
915 \since 5.3
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.
920
921 This function requires the value type to have an implementation of
922 \c operator==().
923
924 \sa indexOf(), contains()
925*/
926
927/*! \fn template<class T, qsizetype Prealloc> template <typename AT = T> bool QVarLengthArray<T, Prealloc>::contains(const AT &value) const
928
929 \since 5.3
930 Returns \c true if the array contains an occurrence of \a value;
931 otherwise returns \c false.
932
933 This function requires the value type to have an implementation of
934 \c operator==().
935
936 \sa indexOf(), lastIndexOf()
937*/
938
939/*!
940 \fn template <typename T, qsizetype Prealloc> size_t qHash(const QVarLengthArray<T, Prealloc> &key, size_t seed = 0)
941 \relates QVarLengthArray
942 \since 5.14
943
944 Returns the hash value for \a key, using \a seed to seed the
945 calculation.
946*/
947
948/*! \fn template <typename T, qsizetype Prealloc> template <typename AT = T> qsizetype QVarLengthArray<T, Prealloc>::removeAll(const AT &t)
949 \since 6.1
950
951 Removes all elements that compare equal to \a t from the
952 array. Returns the number of elements removed, if any.
953
954 \sa removeOne()
955*/
956
957/*! \fn template <typename T, qsizetype Prealloc> template <typename AT = T> bool QVarLengthArray<T, Prealloc>::removeOne(const AT &t)
958 \since 6.1
959
960 Removes the first element that compares equal to \a t from the
961 array. Returns whether an element was, in fact, removed.
962
963 \sa removeAll()
964*/
965
966/*! \fn template <typename T, qsizetype Prealloc> template <typename Predicate> qsizetype QVarLengthArray<T, Prealloc>::removeIf(Predicate pred)
967 \since 6.1
968
969 Removes all elements for which the predicate \a pred returns true
970 from the array. Returns the number of elements removed, if any.
971
972 \sa removeAll()
973*/
974
975/*! \fn template <typename T, qsizetype Prealloc, typename AT> qsizetype erase(QVarLengthArray<T, Prealloc> &array, const AT &t)
976 \relates QVarLengthArray
977 \since 6.1
978
979 Removes all elements that compare equal to \a t from the
980 array \a array. Returns the number of elements removed, if any.
981
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.
985
986 \sa erase_if()
987*/
988
989/*! \fn template <typename T, qsizetype Prealloc, typename Predicate> qsizetype erase_if(QVarLengthArray<T, Prealloc> &array, Predicate pred)
990 \relates QVarLengthArray
991 \since 6.1
992
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
995 any.
996
997 \sa erase()
998*/
999
1000/*! \fn template <class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::assign(qsizetype n, const T &t)
1001 \since 6.6
1002
1003 Replaces the contents of this container with \a n copies of \a t.
1004
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.
1007*/
1008
1009/*! \fn template <class T, qsizetype Prealloc> template <typename InputIterator, if_input_iterator<InputIterator>> QVarLengthArray<T, Prealloc>::assign(InputIterator first, InputIterator last)
1010 \since 6.6
1011
1012 Replaces the contents of this container with a copy of the elements in the
1013 iterator range [\a first, \a last).
1014
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.
1018
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}.
1022
1023 The behavior is undefined if either argument is an iterator into *this.
1024*/
1025
1026/*! \fn template <class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::assign(std::initializer_list<T> list)
1027 \since 6.6
1028
1029 Replaces the contents of this container with a copy of the elements of \a list.
1030
1031 The size of this container will be equal to the number of elements in \a list.
1032
1033 This function only allocates memory if the number of elements in \a list
1034 exceeds the capacity of the container.
1035*/