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. 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
The value type of \c InputIterator must be convertible to \c T.
109
110
\constraints
111
\c InputIterator meets the requirements of an
112
\l {https://en.cppreference.com/w/cpp/named_req/InputIterator} {LegacyInputIterator}.
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() const
144
\fn template<class T, qsizetype Prealloc> qsizetype QVarLengthArray<T, Prealloc>::maxSize()
145
\since 6.8
146
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<typename T, qsizetype Prealloc1, qsizetype Prealloc2> auto operator<=>(const QVarLengthArray<T,Prealloc1> &lhs, const QVarLengthArray<T,Prealloc2> &rhs)
880
\since 6.9
881
\relates QVarLengthArray
882
883
Compares the contents of \a lhs and \a rhs
884
\l {https://en.cppreference.com/w/cpp/algorithm/lexicographical_compare_three_way}
885
{lexicographically}. Returns the result of the strongest applicable category
886
type, that is \c {decltype(lhs[0] <=> rhs[0])} if \c {operator<=>()} is
887
available for type \c {T}; otherwise \c {std::weak_ordering}.
888
889
\note This operator is only available in C++20 mode, and when the underlying
890
type \c T models the \c {std::three_way_comparable} concept
891
or provides \c {operator<()}.
892
*/
893
894
/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc> &QVarLengthArray<T, Prealloc>::operator<<(const T &value)
895
896
\since 4.8
897
Appends \a value to the array and returns a reference to this
898
vector.
899
900
\sa append(), operator+=()
901
*/
902
903
/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc> &QVarLengthArray<T, Prealloc>::operator<<(T &&value)
904
\since 5.11
905
906
\overload
907
908
\sa append(), operator+=()
909
*/
910
911
/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc> &QVarLengthArray<T, Prealloc>::operator+=(const T &value)
912
913
\since 4.8
914
Appends \a value to the array and returns a reference to this vector.
915
916
\sa append(), operator<<()
917
*/
918
919
/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc> &QVarLengthArray<T, Prealloc>::operator+=(T &&value)
920
\since 5.11
921
922
\overload
923
924
\sa append(), operator<<()
925
*/
926
927
/*! \fn template<class T, qsizetype Prealloc> template <typename AT = T> qsizetype QVarLengthArray<T, Prealloc>::indexOf(const AT &value, qsizetype from = 0) const
928
929
\since 5.3
930
Returns the index position of the first occurrence of \a value in
931
the array, searching forward from index position \a from.
932
Returns -1 if no item matched.
933
934
This function requires the value type to have an implementation of
935
\c operator==().
936
937
\sa lastIndexOf(), contains()
938
*/
939
940
/*! \fn template<class T, qsizetype Prealloc> template <typename AT = T> qsizetype QVarLengthArray<T, Prealloc>::lastIndexOf(const AT &value, qsizetype from = -1) const
941
942
\since 5.3
943
Returns the index position of the last occurrence of the value \a
944
value in the array, searching backward from index position \a
945
from. If \a from is -1 (the default), the search starts at the
946
last item. Returns -1 if no item matched.
947
948
This function requires the value type to have an implementation of
949
\c operator==().
950
951
\sa indexOf(), contains()
952
*/
953
954
/*! \fn template<class T, qsizetype Prealloc> template <typename AT = T> bool QVarLengthArray<T, Prealloc>::contains(const AT &value) const
955
956
\since 5.3
957
Returns \c true if the array contains an occurrence of \a value;
958
otherwise returns \c false.
959
960
This function requires the value type to have an implementation of
961
\c operator==().
962
963
\sa indexOf(), lastIndexOf()
964
*/
965
966
/*!
967
\fn template <typename T, qsizetype Prealloc> size_t qHash(const QVarLengthArray<T, Prealloc> &key, size_t seed = 0)
968
\qhasholdT{QVarLengthArray}{T}
969
\since 5.14
970
*/
971
972
/*! \fn template <typename T, qsizetype Prealloc> template <typename AT = T> qsizetype QVarLengthArray<T, Prealloc>::removeAll(const AT &t)
973
\since 6.1
974
975
Removes all elements that compare equal to \a t from the
976
array. Returns the number of elements removed, if any.
977
978
\sa removeOne()
979
*/
980
981
/*! \fn template <typename T, qsizetype Prealloc> template <typename AT = T> bool QVarLengthArray<T, Prealloc>::removeOne(const AT &t)
982
\since 6.1
983
984
Removes the first element that compares equal to \a t from the
985
array. Returns whether an element was, in fact, removed.
986
987
\sa removeAll()
988
*/
989
990
/*! \fn template <typename T, qsizetype Prealloc> template <typename Predicate> qsizetype QVarLengthArray<T, Prealloc>::removeIf(Predicate pred)
991
\since 6.1
992
993
Removes all elements for which the predicate \a pred returns true
994
from the array. Returns the number of elements removed, if any.
995
996
\sa removeAll()
997
*/
998
999
/*! \fn template <typename T, qsizetype Prealloc, typename AT> qsizetype erase(QVarLengthArray<T, Prealloc> &array, const AT &t)
1000
\relates QVarLengthArray
1001
\since 6.1
1002
1003
Removes all elements that compare equal to \a t from the
1004
array \a array. Returns the number of elements removed, if any.
1005
1006
\note \a t is not allowed to be a reference to an element inside \a
1007
array. If you cannot be sure that this is not the case, take a copy
1008
of \a t and call this function with the copy.
1009
1010
\sa erase_if()
1011
*/
1012
1013
/*! \fn template <typename T, qsizetype Prealloc, typename Predicate> qsizetype erase_if(QVarLengthArray<T, Prealloc> &array, Predicate pred)
1014
\relates QVarLengthArray
1015
\since 6.1
1016
1017
Removes all elements for which the predicate \a pred returns true
1018
from the list \a array. Returns the number of elements removed, if
1019
any.
1020
1021
\sa erase()
1022
*/
1023
1024
/*! \fn template <class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>& QVarLengthArray<T, Prealloc>::assign(qsizetype n, const T &t)
1025
\since 6.6
1026
1027
Replaces the contents of this container with \a n copies of \a t.
1028
1029
The size of this container will be equal to \a n. This function will only
1030
allocate memory if \a n exceeds the capacity of the container.
1031
*/
1032
1033
/*! \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)
1034
\since 6.6
1035
1036
Replaces the contents of this container with a copy of the elements in the
1037
iterator range [\a first, \a last).
1038
1039
The size of this container will be equal to the number of elements in the
1040
range [\a first, \a last). This function will only allocate memory if the
1041
number of elements in the range exceeds the capacity of the container.
1042
1043
The behavior is undefined if either argument is an iterator into *this.
1044
1045
\constraints
1046
\c InputIterator meets the requirements of an
1047
\l {https://en.cppreference.com/w/cpp/named_req/InputIterator} {LegacyInputIterator}.
1048
*/
1049
1050
/*! \fn template <class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>& QVarLengthArray<T, Prealloc>::assign(std::initializer_list<T> list)
1051
\since 6.6
1052
1053
Replaces the contents of this container with a copy of the elements of \a list.
1054
1055
The size of this container will be equal to the number of elements in \a list.
1056
1057
This function only allocates memory if the number of elements in \a list
1058
exceeds the capacity of the container.
1059
*/
qtbase
src
corelib
tools
qvarlengtharray.qdoc
Generated on Sun Mar 9 2025 01:10:28 for Qt by
1.13.2