Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
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. The template parameter \a T specifies the element type
38 and \a Prealloc specifies how many elements to preallocate on the
39 stack; if omitted, \a Prealloc defaults to 256.
40
41 QVarLengthArray's value type must be an \l{assignable data type}.
42 This covers most data types that are commonly used, but the
43 compiler won't let you, for example, store a QWidget as a value;
44 instead, store a QWidget *.
45
46 QVarLengthArray, like QList, provides a resizable array data
47 structure. The main differences between the two classes are:
48
49 \list
50 \li QVarLengthArray's API is much more low-level and it lacks
51 some of QList's functionality.
52
53 \li QVarLengthArray doesn't initialize the memory if the value is
54 a basic type. (QList always does.)
55
56 \li QList uses \l{implicit sharing} as a memory optimization.
57 QVarLengthArray doesn't provide that feature; however, it
58 usually produces slightly better performance due to reduced
59 overhead, especially in tight loops.
60 \endlist
61
62 In summary, QVarLengthArray is a low-level optimization class
63 that only makes sense in very specific cases. It is used a few
64 places inside Qt and was added to Qt's public API for the
65 convenience of advanced users.
66
67 \sa QList
68*/
69
70/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::QVarLengthArray()
71
72 Constructs an array with an initial size of zero.
73*/
74
75/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::QVarLengthArray(qsizetype size)
76
77 Constructs an array with an initial size of \a size elements.
78
79 If the value type is a primitive type (e.g., char, int, float) or
80 a pointer type (e.g., QWidget *), the elements are not
81 initialized. For other types, the elements are initialized with a
82 \l{default-constructed value}.
83*/
84
85/*!
86 \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::QVarLengthArray(qsizetype size, const T &v)
87 \since 6.4
88
89 Constructs an array with an initial size of \a size elements filled with
90 copies of \a v.
91
92 \note This constructor is only available when \c T is copy-constructible.
93
94 \sa size(), squeeze()
95*/
96
97
98/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::QVarLengthArray(std::initializer_list<T> args)
99 \since 5.5
100
101 Constructs an array from the std::initializer_list given by \a args.
102*/
103
104/*! \fn template<class T, qsizetype Prealloc> template<typename InputIterator, QVarLengthArray<T, Prealloc>::if_input_iterator<InputIterator>> QVarLengthArray<T, Prealloc>::QVarLengthArray(InputIterator first, InputIterator last)
105 \since 5.14
106
107 Constructs an array with the contents in the iterator range [\a first, \a last).
108
109 The value type of \c InputIterator must be convertible to \c T.
110
111 \constraints
112 \c InputIterator meets the requirements of an
113 \l {https://en.cppreference.com/w/cpp/named_req/InputIterator} {LegacyInputIterator}.
114*/
115
116
117/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::~QVarLengthArray()
118
119 Destroys the array.
120*/
121
122/*! \fn template<class T, qsizetype Prealloc> qsizetype QVarLengthArray<T, Prealloc>::size() const
123
124 Returns the number of elements in the array.
125
126 \sa isEmpty(), resize()
127*/
128
129/*! \fn template<class T, qsizetype Prealloc> qsizetype QVarLengthArray<T, Prealloc>::count() const
130
131 Same as size().
132
133 \sa isEmpty(), resize()
134*/
135
136/*! \fn template<class T, qsizetype Prealloc> qsizetype QVarLengthArray<T, Prealloc>::length() const
137 \since 5.0
138
139 Same as size().
140
141 \sa isEmpty(), resize()
142*/
143
144/*! \fn template<class T, qsizetype Prealloc> qsizetype QVarLengthArray<T, Prealloc>::max_size() const
145 \fn template<class T, qsizetype Prealloc> qsizetype QVarLengthArray<T, Prealloc>::maxSize()
146 \since 6.8
147
148 It returns the maximum number of elements that the array can
149 theoretically hold. In practice, the number can be much smaller,
150 limited by the amount of memory available to the system.
151*/
152
153/*! \fn template<class T, qsizetype Prealloc> T& QVarLengthArray<T, Prealloc>::first()
154
155 Returns a reference to the first item in the array. The array must
156 not be empty. If the array can be empty, check isEmpty() before
157 calling this function.
158
159 \sa last(), isEmpty()
160*/
161
162/*! \fn template<class T, qsizetype Prealloc> const T& QVarLengthArray<T, Prealloc>::first() const
163
164 \overload
165*/
166
167/*! \fn template<class T, qsizetype Prealloc> T& QVarLengthArray<T, Prealloc>::front()
168 \since 5.0
169
170 Same as first(). Provided for STL-compatibility.
171*/
172
173/*! \fn template<class T, qsizetype Prealloc> const T& QVarLengthArray<T, Prealloc>::front() const
174 \since 5.0
175
176 \overload
177*/
178
179/*! \fn template<class T, qsizetype Prealloc> T& QVarLengthArray<T, Prealloc>::last()
180
181 Returns a reference to the last item in the array. The array must
182 not be empty. If the array can be empty, check isEmpty() before
183 calling this function.
184
185 \sa first(), isEmpty()
186*/
187
188/*! \fn template<class T, qsizetype Prealloc> const T& QVarLengthArray<T, Prealloc>::last() const
189
190 \overload
191*/
192
193/*! \fn template<class T, qsizetype Prealloc> T& QVarLengthArray<T, Prealloc>::back()
194 \since 5.0
195
196 Same as last(). Provided for STL-compatibility.
197*/
198
199/*! \fn template<class T, qsizetype Prealloc> const T& QVarLengthArray<T, Prealloc>::back() const
200 \since 5.0
201
202 \overload
203*/
204
205/*! \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::shrink_to_fit()
206 \since 5.10
207
208 Same as squeeze(). Provided for STL-compatibility.
209*/
210
211/*! \fn template<class T, qsizetype Prealloc> bool QVarLengthArray<T, Prealloc>::isEmpty() const
212
213 Returns \c true if the array has size 0; otherwise returns \c false.
214
215 \sa size(), resize()
216*/
217
218/*! \fn template<class T, qsizetype Prealloc> bool QVarLengthArray<T, Prealloc>::empty() const
219 \since 5.0
220
221 Returns \c true if the array has size 0; otherwise returns \c false.
222
223 Same as isEmpty(). Provided for STL-compatibility.
224*/
225
226/*! \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::clear()
227
228 Removes all the elements from the array.
229
230 Same as resize(0).
231*/
232
233/*! \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::resize(qsizetype size)
234
235 Sets the size of the array to \a size. If \a size is greater than
236 the current size, elements are added to the end. If \a size is
237 less than the current size, elements are removed from the end.
238
239 If the value type is a primitive type (e.g., char, int, float) or
240 a pointer type (e.g., QWidget *), new elements are not
241 initialized. For other types, the elements are initialized with a
242 \l{default-constructed value}.
243
244 \sa size(), squeeze()
245*/
246
247/*!
248 \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::resize(qsizetype size, const T &v)
249 \since 6.4
250
251 Sets the size of the array to \a size. If \a size is greater than
252 the current size, copies of \a v are added to the end. If \a size is
253 less than the current size, elements are removed from the end.
254
255 \note This function is only available when \c T is copy-constructible.
256
257 \sa size(), squeeze()
258*/
259
260/*! \fn template<class T, qsizetype Prealloc> qsizetype QVarLengthArray<T, Prealloc>::capacity() const
261
262 Returns the maximum number of elements that can be stored in the
263 array without forcing a reallocation.
264
265 The sole purpose of this function is to provide a means of fine
266 tuning QVarLengthArray's memory usage. In general, you will rarely ever
267 need to call this function. If you want to know how many items are
268 in the array, call size().
269
270 \sa reserve(), squeeze()
271*/
272
273/*! \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::reserve(qsizetype size)
274
275 Attempts to allocate memory for at least \a size elements. If you
276 know in advance how large the array can get, you can call this
277 function and if you call resize() often, you are likely to get
278 better performance. If \a size is an underestimate, the worst
279 that will happen is that the QVarLengthArray will be a bit
280 slower.
281
282 The sole purpose of this function is to provide a means of fine
283 tuning QVarLengthArray's memory usage. In general, you will
284 rarely ever need to call this function. If you want to change the
285 size of the array, call resize().
286
287 \sa capacity(), squeeze()
288*/
289
290/*! \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::squeeze()
291 \since 5.1
292
293 Releases any memory not required to store the items.
294 If the container can fit its storage on the stack allocation,
295 it will free the heap allocation and copy the elements back to the stack.
296
297 The sole purpose of this function is to provide a means of fine
298 tuning QVarLengthArray's memory usage. In general, you will rarely ever
299 need to call this function.
300
301 \sa reserve(), capacity(), resize()
302*/
303
304/*! \fn template<class T, qsizetype Prealloc> T &QVarLengthArray<T, Prealloc>::operator[](qsizetype i)
305
306 Returns a reference to the item at index position \a i.
307
308//! [valid-i]
309 \a i must be a valid index position in the array (i.e., 0 <= \a i
310 < size()).
311//! [valid-i]
312
313 \sa data(), at()
314*/
315
316/*! \fn template<class T, qsizetype Prealloc> const T &QVarLengthArray<T, Prealloc>::operator[](qsizetype i) const
317
318 \overload
319*/
320
321
322/*!
323 \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::append(const T &t)
324
325 Appends item \a t to the array, extending the array if necessary.
326
327 \sa removeLast()
328*/
329
330/*!
331 \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::push_back(const T &t)
332 \since 5.0
333
334 Appends item \a t to the array, extending the array if necessary.
335 Provided for STL-compatibility.
336*/
337
338/*!
339 \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::append(T &&t)
340 \overload append
341 \since 5.9
342
343 \note Unlike the lvalue overload of append(), passing a reference to
344 an object that is already an element of \c *this leads to undefined
345 behavior:
346
347 \code
348 vla.append(std::move(vla[0])); // BUG: passing an object that is already in the container
349 \endcode
350*/
351
352/*!
353 \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::push_back(T &&t)
354 \overload push_back
355 \since 5.9
356
357 \note Unlike the lvalue overload of push_back(), passing a reference to
358 an object that is already an element of \c *this leads to undefined
359 behavior:
360
361 \code
362 vla.push_back(std::move(vla[0])); // BUG: passing an object that is already in the container
363 \endcode
364*/
365
366/*!
367 \fn template<class T, qsizetype Prealloc> inline void QVarLengthArray<T, Prealloc>::removeLast()
368 \since 4.5
369
370 Decreases the size of the array by one. The allocated size is not changed.
371
372 \sa append()
373*/
374
375/*!
376 \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::pop_back()
377 \since 5.0
378
379 Same as removeLast(). Provided for STL-compatibility.
380*/
381
382/*!
383 \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::append(const T *buf, qsizetype size)
384
385 Appends \a size amount of items referenced by \a buf to this array.
386*/
387
388
389/*! \fn template<class T, qsizetype Prealloc> T *QVarLengthArray<T, Prealloc>::data()
390
391 Returns a pointer to the data stored in the array. The pointer can
392 be used to access and modify the items in the array.
393
394 Example:
395 \snippet code/doc_src_qvarlengtharray.cpp 3
396
397 The pointer remains valid as long as the array isn't reallocated.
398
399 This function is mostly useful to pass an array to a function
400 that accepts a plain C++ array.
401
402 \sa constData(), operator[]()
403*/
404
405/*! \fn template<class T, qsizetype Prealloc> const T *QVarLengthArray<T, Prealloc>::data() const
406
407 \overload
408*/
409
410/*! \fn template<class T, qsizetype Prealloc> const T *QVarLengthArray<T, Prealloc>::constData() const
411
412 Returns a const pointer to the data stored in the array. The
413 pointer can be used to access the items in the array. The
414 pointer remains valid as long as the array isn't reallocated.
415
416 This function is mostly useful to pass an array to a function
417 that accepts a plain C++ array.
418
419 \sa data(), operator[]()
420*/
421
422/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc> &QVarLengthArray<T, Prealloc>::operator=(const QVarLengthArray<T, Prealloc> &other)
423 Assigns \a other to this array and returns a reference to this array.
424 */
425
426/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc> &QVarLengthArray<T, Prealloc>::operator=(QVarLengthArray<T, Prealloc> &&other)
427 Move-assigns \a other to this array and returns a reference to this array.
428 After the move, \a other is empty.
429 \since 6.0
430 */
431
432/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc> &QVarLengthArray<T, Prealloc>::operator=(std::initializer_list<T> list)
433 \since 5.5
434
435 Assigns the values of \a list to this array, and returns a reference to this array.
436*/
437
438/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::QVarLengthArray(const QVarLengthArray<T, Prealloc> &other)
439 Constructs a copy of \a other.
440 */
441
442/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::QVarLengthArray(QVarLengthArray<T, Prealloc> &&other)
443 Move-constructs this variable-length array from \a other. After the move, \a other is empty.
444 \since 6.0
445 */
446
447/*! \fn template<class T, qsizetype Prealloc> const T &QVarLengthArray<T, Prealloc>::at(qsizetype i) const
448
449 Returns a reference to the item at index position \a i.
450
451 \include qvarlengtharray.qdoc valid-i
452
453 \sa value(), operator[]()
454*/
455
456/*! \fn template<class T, qsizetype Prealloc> T QVarLengthArray<T, Prealloc>::value(qsizetype i) const
457
458 Returns the value at index position \a i.
459
460 If the index \a i is out of bounds, the function returns
461 a \l{default-constructed value}. If you are certain that
462 \a i is within bounds, you can use at() instead, which is slightly
463 faster.
464
465 \sa at(), operator[]()
466*/
467
468/*! \fn template<class T, qsizetype Prealloc> T QVarLengthArray<T, Prealloc>::value(qsizetype i, const T &defaultValue) const
469
470 \overload
471
472 If the index \a i is out of bounds, the function returns
473 \a defaultValue.
474*/
475
476/*
477 \var QVarLengthArray::PreallocatedSize
478 \since 6.8
479
480 The same value as the \c{Prealloc} template argument. Provided for easier
481 access compared to manually extracting the value from the template
482 argument.
483*/
484
485/*!
486 \typedef QVarLengthArray::size_type
487 \since 4.7
488
489 Typedef for int. Provided for STL compatibility.
490*/
491
492/*!
493 \typedef QVarLengthArray::value_type
494 \since 4.7
495
496 Typedef for T. Provided for STL compatibility.
497*/
498
499/*!
500 \typedef QVarLengthArray::difference_type
501 \since 4.7
502
503 Typedef for ptrdiff_t. Provided for STL compatibility.
504*/
505
506/*!
507 \typedef QVarLengthArray::pointer
508 \since 4.7
509
510 Typedef for T *. Provided for STL compatibility.
511*/
512
513/*!
514 \typedef QVarLengthArray::const_pointer
515 \since 4.7
516
517 Typedef for const T *. Provided for STL compatibility.
518*/
519
520/*!
521 \typedef QVarLengthArray::reference
522 \since 4.7
523
524 Typedef for T &. Provided for STL compatibility.
525*/
526
527/*!
528 \typedef QVarLengthArray::const_reference
529 \since 4.7
530
531 Typedef for const T &. Provided for STL compatibility.
532*/
533
534/*!
535 \typedef QVarLengthArray::const_iterator
536 \since 4.7
537
538 Typedef for const T *. Provided for STL compatibility.
539*/
540
541/*!
542 \typedef QVarLengthArray::iterator
543 \since 4.7
544
545 Typedef for T *. Provided for STL compatibility.
546*/
547
548/*!
549 \typedef QVarLengthArray::const_reverse_iterator
550 \since 5.6
551
552 Typedef for \c{std::reverse_iterator<const T*>}. Provided for STL compatibility.
553*/
554
555/*!
556 \typedef QVarLengthArray::reverse_iterator
557 \since 5.6
558
559 Typedef for \c{std::reverse_iterator<T*>}. Provided for STL compatibility.
560*/
561
562/*!
563 \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::prepend(const T &value)
564 \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::prepend(T &&value)
565
566 \since 4.8
567 \deprecated [6.3] This is slow. If you must, use \c{insert(cbegin(), ~~~)} instead.
568
569 Inserts \a value at the beginning of the array.
570
571
572 This is the same as vector.insert(0, \a value).
573
574 For large arrays, this operation can be slow (\l{linear time}),
575 because it requires moving all the items in the vector by one
576 position further in memory. If you want a container class that
577 provides a fast prepend() function, use std::list instead.
578
579 \sa append(), insert()
580*/
581
582/*! \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::replace(qsizetype i, const T &value)
583
584 \since 4.8
585 Replaces the item at index position \a i with \a value.
586
587 \include qvarlengtharray.qdoc valid-i
588
589 \sa operator[](), remove()
590*/
591
592/*! \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::remove(qsizetype i, qsizetype count)
593
594 \overload
595 \since 4.8
596
597 Removes \a count elements from the array, starting at
598 index position \a i.
599
600 \include qvarlengtharray.qdoc valid-i
601 \a count must be <= size() - \a i.
602 \a i == size() is allowed if \a count == 0.
603
604 \sa insert(), replace()
605*/
606
607/*!
608 \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::removeAt(qsizetype i)
609 \since 6.12
610
611 Removes the element at position \a i from the array.
612
613 \include qvarlengtharray.qdoc valid-i
614
615 This function is provided for compatibility with QList.
616
617 \sa insert(), replace()
618*/
619
620/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::iterator QVarLengthArray<T, Prealloc>::begin()
621 \since 4.8
622
623 Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first item in
624 the array.
625
626 \sa constBegin(), end()
627*/
628
629/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::const_iterator QVarLengthArray<T, Prealloc>::begin() const
630 \since 4.8
631 \overload
632*/
633
634/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::const_iterator QVarLengthArray<T, Prealloc>::cbegin() const
635 \since 5.0
636
637 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item
638 in the array.
639
640 \sa begin(), cend()
641*/
642
643/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::const_iterator QVarLengthArray<T, Prealloc>::constBegin() const
644 \since 4.8
645
646 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item
647 in the array.
648
649 \sa begin(), constEnd()
650*/
651
652/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::iterator QVarLengthArray<T, Prealloc>::end()
653 \since 4.8
654
655 Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item
656 after the last item in the array.
657
658 \sa begin(), constEnd()
659*/
660
661/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::const_iterator QVarLengthArray<T, Prealloc>::end() const
662 \since 4.8
663
664 \overload
665*/
666
667/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::const_iterator QVarLengthArray<T, Prealloc>::cend() const
668 \since 5.0
669
670 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary
671 item after the last item in the array.
672
673 \sa cbegin(), end()
674*/
675
676/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::const_iterator QVarLengthArray<T, Prealloc>::constEnd() const
677 \since 4.8
678
679 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary
680 item after the last item in the array.
681
682 \sa constBegin(), end()
683*/
684
685/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::reverse_iterator QVarLengthArray<T, Prealloc>::rbegin()
686 \since 5.6
687
688 Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to the first
689 item in the variable length array, in reverse order.
690
691 \sa begin(), crbegin(), rend()
692*/
693
694/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::const_reverse_iterator QVarLengthArray<T, Prealloc>::rbegin() const
695 \since 5.6
696 \overload
697*/
698
699/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::const_reverse_iterator QVarLengthArray<T, Prealloc>::crbegin() const
700 \since 5.6
701
702 Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing to the first
703 item in the variable length array, in reverse order.
704
705 \sa begin(), rbegin(), rend()
706*/
707
708/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::reverse_iterator QVarLengthArray<T, Prealloc>::rend()
709 \since 5.6
710
711 Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to one past
712 the last item in the variable length array, in reverse order.
713
714 \sa end(), crend(), rbegin()
715*/
716
717/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::const_reverse_iterator QVarLengthArray<T, Prealloc>::rend() const
718 \since 5.6
719 \overload
720*/
721
722/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::const_reverse_iterator QVarLengthArray<T, Prealloc>::crend() const
723 \since 5.6
724
725 Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing to one
726 past the last item in the variable length array, in reverse order.
727
728 \sa end(), rend(), rbegin()
729*/
730
731/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::iterator QVarLengthArray<T, Prealloc>::erase(const_iterator pos)
732 \since 4.8
733
734 Removes the item pointed to by the iterator \a pos from the
735 vector, and returns an iterator to the next item in the vector
736 (which may be end()).
737
738 \sa insert(), remove()
739*/
740
741/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::iterator QVarLengthArray<T, Prealloc>::erase(const_iterator begin, const_iterator end)
742
743 \overload
744 \since 4.8
745
746 Removes all the items from \a begin up to (but not including) \a
747 end. Returns an iterator to the same item that \a end referred to
748 before the call.
749*/
750
751/*!
752 \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::insert(qsizetype i, const T &value)
753 \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::insert(qsizetype i, T &&value)
754 \since 4.8
755
756 Inserts \a value at index position \a i in the array. If \a i is
757 0, the value is prepended to the vector. If \a i is size(), the
758 value is appended to the vector.
759
760 For large arrays, this operation can be slow (\l{linear time}),
761 because it requires moving all the items at indexes \a i and
762 above by one position further in memory. If you want a container
763 class that provides a fast insert() function, use std::list
764 instead.
765
766 \sa remove()
767*/
768
769/*! \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::insert(qsizetype i, qsizetype count, const T &value)
770
771 \overload
772 \since 4.8
773
774 Inserts \a count copies of \a value at index position \a i in the
775 vector.
776*/
777
778/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::iterator QVarLengthArray<T, Prealloc>::insert(const_iterator before, const T &value)
779 \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::iterator QVarLengthArray<T, Prealloc>::insert(const_iterator before, T &&value)
780
781 \overload
782 \since 4.8
783
784 Inserts \a value in front of the item pointed to by the iterator
785 \a before. Returns an iterator pointing at the inserted item.
786*/
787
788/*!
789 \fn template <class T, qsizetype Prealloc> template <typename...Args> QVarLengthArray<T, Prealloc>::iterator QVarLengthArray<T, Prealloc>::emplace(const_iterator pos, Args &&...args)
790
791 \since 6.3
792
793 Inserts an item in front of the item pointed to by the iterator
794 \a pos, passing \a args to its constructor.
795
796 Returns an iterator pointing at the emplaced item.
797*/
798
799/*!
800 \fn template <class T, qsizetype Prealloc> template <typename...Args> T &QVarLengthArray<T, Prealloc>::emplace_back(Args &&...args)
801 \since 6.3
802
803 Inserts an item at the back of this QVarLengthArray, passing
804 \a args to its constructor.
805
806 Returns a reference to the emplaced item.
807*/
808
809/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::iterator QVarLengthArray<T, Prealloc>::insert(const_iterator before, qsizetype count, const T &value)
810
811 \since 4.8
812 Inserts \a count copies of \a value in front of the item pointed to
813 by the iterator \a before. Returns an iterator pointing at the
814 first of the inserted items.
815*/
816
817
818
819/*! \fn template<class T, qsizetype Prealloc1, qsizetype Prealloc2> bool operator==(const QVarLengthArray<T, Prealloc1> &left, const QVarLengthArray<T, Prealloc2> &right)
820
821 \relates QVarLengthArray
822 \since 4.8
823 Returns \c true if the two arrays, specified by \a left and \a right, are
824 equal. The preallocation sizes \a Prealloc1 and \a Prealloc2 may differ.
825
826 Two arrays are considered equal if they contain the same values
827 in the same order.
828
829 This function requires the value type to have an implementation
830 of \c operator==().
831
832 \sa {operator!=(const QVarLengthArray<T, Prealloc1> &left, const QVarLengthArray<T, Prealloc2> &right)}{operator!=()}
833*/
834
835/*! \fn template<typename T, qsizetype Prealloc1, qsizetype Prealloc2> bool operator!=(const QVarLengthArray<T, Prealloc1> &left, const QVarLengthArray<T, Prealloc2> &right)
836
837 \relates QVarLengthArray
838 \since 4.8
839 Returns \c true if the two arrays, specified by \a left and \a right, are
840 \e not equal. The preallocation sizes \a Prealloc1 and \a Prealloc2 may
841 differ.
842
843 Two arrays are considered equal if they contain the same values
844 in the same order.
845
846 This function requires the value type to have an implementation
847 of \c operator==().
848
849 \sa {operator==(const QVarLengthArray<T, Prealloc1> &left, const QVarLengthArray<T, Prealloc2> &right)}{operator==()}
850*/
851
852/*! \fn template<typename T, qsizetype Prealloc1, qsizetype Prealloc2> bool operator<(const QVarLengthArray<T,Prealloc1> &lhs, const QVarLengthArray<T,Prealloc2> &rhs)
853 \since 5.6
854 \relates QVarLengthArray
855
856 Returns \c true if variable length array \a lhs is
857 \l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare}
858 {lexicographically less than} \a rhs; otherwise returns \c false. The
859 preallocation sizes \a Prealloc1 and \a Prealloc2 may differ.
860
861 This function requires the value type to have an implementation
862 of \c operator<().
863*/
864
865/*! \fn template<typename T, qsizetype Prealloc1, qsizetype Prealloc2> bool operator<=(const QVarLengthArray<T,Prealloc1> &lhs, const QVarLengthArray<T,Prealloc2> &rhs)
866 \since 5.6
867 \relates QVarLengthArray
868
869 Returns \c true if variable length array \a lhs is
870 \l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare}
871 {lexicographically less than or equal to} \a rhs; otherwise returns
872 \c false. The preallocation sizes \a Prealloc1 and \a Prealloc2 may differ.
873
874 This function requires the value type to have an implementation
875 of \c operator<().
876*/
877
878/*! \fn template<typename T, qsizetype Prealloc1, qsizetype Prealloc2> bool operator>(const QVarLengthArray<T,Prealloc1> &lhs, const QVarLengthArray<T,Prealloc2> &rhs)
879 \since 5.6
880 \relates QVarLengthArray
881
882 Returns \c true if variable length array \a lhs is
883 \l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare}
884 {lexicographically greater than} \a rhs; otherwise returns \c false. The
885 preallocation sizes \a Prealloc1 and \a Prealloc2 may differ.
886
887 This function requires the value type to have an implementation
888 of \c operator<().
889*/
890
891/*! \fn template<typename T, qsizetype Prealloc1, qsizetype Prealloc2> bool operator>=(const QVarLengthArray<T,Prealloc1> &lhs, const QVarLengthArray<T,Prealloc2> &rhs)
892 \since 5.6
893 \relates QVarLengthArray
894
895 Returns \c true if variable length array \a lhs is
896 \l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare}
897 {lexicographically greater than or equal to} \a rhs; otherwise returns
898 \c false. The preallocation sizes \a Prealloc1 and \a Prealloc2 may differ.
899
900 This function requires the value type to have an implementation
901 of \c operator<().
902*/
903
904/*! \fn template<typename T, qsizetype Prealloc1, qsizetype Prealloc2> auto operator<=>(const QVarLengthArray<T,Prealloc1> &lhs, const QVarLengthArray<T,Prealloc2> &rhs)
905 \since 6.9
906 \relates QVarLengthArray
907
908 Compares the contents of \a lhs and \a rhs
909 \l {https://en.cppreference.com/w/cpp/algorithm/lexicographical_compare_three_way}
910 {lexicographically}. The preallocation sizes \a Prealloc1 and \a Prealloc2 may
911 differ. Returns the result of the strongest applicable category type, that is
912 \c {decltype(lhs[0] <=> rhs[0])} if \c {operator<=>()} is available for type
913 \c {T}; otherwise \c {std::weak_ordering}.
914
915 \note This operator is only available in C++20 mode, and when the underlying
916 type \c T models the \c {std::three_way_comparable} concept
917 or provides \c {operator<()}.
918*/
919
920/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc> &QVarLengthArray<T, Prealloc>::operator<<(const T &value)
921
922 \since 4.8
923 Appends \a value to the array and returns a reference to this
924 vector.
925
926 \sa append(), operator+=()
927*/
928
929/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc> &QVarLengthArray<T, Prealloc>::operator<<(T &&value)
930 \since 5.11
931
932 \overload
933
934 \sa append(), operator+=()
935*/
936
937/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc> &QVarLengthArray<T, Prealloc>::operator+=(const T &value)
938
939 \since 4.8
940 Appends \a value to the array and returns a reference to this vector.
941
942 \sa append(), operator<<()
943*/
944
945/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc> &QVarLengthArray<T, Prealloc>::operator+=(T &&value)
946 \since 5.11
947
948 \overload
949
950 \sa append(), operator<<()
951*/
952
953/*! \fn template<class T, qsizetype Prealloc> template <typename AT = T> qsizetype QVarLengthArray<T, Prealloc>::indexOf(const AT &value, qsizetype from = 0) const
954
955 \since 5.3
956 Returns the index position of the first occurrence of \a value in
957 the array, searching forward from index position \a from.
958 Returns -1 if no item matched.
959
960 This function requires the value type to have an implementation of
961 \c operator==().
962
963 \sa lastIndexOf(), contains()
964*/
965
966/*! \fn template<class T, qsizetype Prealloc> template <typename AT = T> qsizetype QVarLengthArray<T, Prealloc>::lastIndexOf(const AT &value, qsizetype from = -1) const
967
968 \since 5.3
969 Returns the index position of the last occurrence of the value \a
970 value in the array, searching backward from index position \a
971 from. If \a from is -1 (the default), the search starts at the
972 last item. Returns -1 if no item matched.
973
974 This function requires the value type to have an implementation of
975 \c operator==().
976
977 \sa indexOf(), contains()
978*/
979
980/*! \fn template<class T, qsizetype Prealloc> template <typename AT = T> bool QVarLengthArray<T, Prealloc>::contains(const AT &value) const
981
982 \since 5.3
983 Returns \c true if the array contains an occurrence of \a value;
984 otherwise returns \c false.
985
986 This function requires the value type to have an implementation of
987 \c operator==().
988
989 \sa indexOf(), lastIndexOf()
990*/
991
992/*!
993 \fn template <typename T, qsizetype Prealloc> size_t qHash(const QVarLengthArray<T, Prealloc> &key, size_t seed = 0)
994 \qhasholdT{QVarLengthArray}{T}
995 \since 5.14
996
997 Returns the hash value for the \a key, using \a seed to seed the
998 calculation. The preallocation size \a Prealloc does not affect the hash.
999*/
1000
1001/*! \fn template <typename T, qsizetype Prealloc> template <typename AT = T> qsizetype QVarLengthArray<T, Prealloc>::removeAll(const AT &t)
1002 \since 6.1
1003
1004 Removes all elements that compare equal to \a t from the
1005 array. Returns the number of elements removed, if any.
1006
1007 \sa removeOne()
1008*/
1009
1010/*! \fn template <typename T, qsizetype Prealloc> template <typename AT = T> bool QVarLengthArray<T, Prealloc>::removeOne(const AT &t)
1011 \since 6.1
1012
1013 Removes the first element that compares equal to \a t from the
1014 array. Returns whether an element was, in fact, removed.
1015
1016 \sa removeAll()
1017*/
1018
1019/*! \fn template <typename T, qsizetype Prealloc> template <typename Predicate> qsizetype QVarLengthArray<T, Prealloc>::removeIf(Predicate pred)
1020 \since 6.1
1021
1022 Removes all elements for which the predicate \a pred returns true
1023 from the array. Returns the number of elements removed, if any.
1024
1025 \sa removeAll()
1026*/
1027
1028/*! \fn template <typename T, qsizetype Prealloc, typename AT> qsizetype erase(QVarLengthArray<T, Prealloc> &array, const AT &t)
1029 \relates QVarLengthArray
1030 \since 6.1
1031
1032 Removes all elements that compare equal to \a t from the
1033 array \a array. Returns the number of elements removed, if any.
1034
1035 \note \a t is not allowed to be a reference to an element inside \a
1036 array. If you cannot be sure that this is not the case, take a copy
1037 of \a t and call this function with the copy.
1038
1039 \sa erase_if()
1040*/
1041
1042/*! \fn template <typename T, qsizetype Prealloc, typename Predicate> qsizetype erase_if(QVarLengthArray<T, Prealloc> &array, Predicate pred)
1043 \relates QVarLengthArray
1044 \since 6.1
1045
1046 Removes all elements for which the predicate \a pred returns true
1047 from the list \a array. Returns the number of elements removed, if
1048 any. The preallocation size \a Prealloc does not affect the operation.
1049
1050 \sa erase()
1051*/
1052
1053/*! \fn template <class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>& QVarLengthArray<T, Prealloc>::assign(qsizetype n, const T &t)
1054 \since 6.6
1055
1056 Replaces the contents of this container with \a n copies of \a t.
1057
1058 The size of this container will be equal to \a n. This function will only
1059 allocate memory if \a n exceeds the capacity of the container.
1060*/
1061
1062/*! \fn template <class T, qsizetype Prealloc> template <typename InputIterator, QVarLengthArray<T, Prealloc>::if_input_iterator<InputIterator>> QVarLengthArray<T, Prealloc>& QVarLengthArray<T, Prealloc>::assign(InputIterator first, InputIterator last)
1063 \since 6.6
1064
1065 Replaces the contents of this container with a copy of the elements in the
1066 iterator range [\a first, \a last).
1067
1068 The size of this container will be equal to the number of elements in the
1069 range [\a first, \a last). This function will only allocate memory if the
1070 number of elements in the range exceeds the capacity of the container.
1071
1072 The behavior is undefined if either argument is an iterator into *this.
1073
1074 \constraints
1075 \c InputIterator meets the requirements of an
1076 \l {https://en.cppreference.com/w/cpp/named_req/InputIterator} {LegacyInputIterator}.
1077*/
1078
1079/*! \fn template <class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>& QVarLengthArray<T, Prealloc>::assign(std::initializer_list<T> list)
1080 \since 6.6
1081
1082 Replaces the contents of this container with a copy of the elements of \a list.
1083
1084 The size of this container will be equal to the number of elements in \a list.
1085
1086 This function only allocates memory if the number of elements in \a list
1087 exceeds the capacity of the container.
1088*/