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