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
\a i must be a valid index position in the array (i.e., 0 <= \a i
309
< size()).
310
311
\sa data(), at()
312
*/
313
314
/*! \fn template<class T, qsizetype Prealloc> const T &QVarLengthArray<T, Prealloc>::operator[](qsizetype i) const
315
316
\overload
317
*/
318
319
320
/*!
321
\fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::append(const T &t)
322
323
Appends item \a t to the array, extending the array if necessary.
324
325
\sa removeLast()
326
*/
327
328
/*!
329
\fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::push_back(const T &t)
330
\since 5.0
331
332
Appends item \a t to the array, extending the array if necessary.
333
Provided for STL-compatibility.
334
*/
335
336
/*!
337
\fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::append(T &&t)
338
\overload append
339
\since 5.9
340
341
\note Unlike the lvalue overload of append(), passing a reference to
342
an object that is already an element of \c *this leads to undefined
343
behavior:
344
345
\code
346
vla.append(std::move(vla[0])); // BUG: passing an object that is already in the container
347
\endcode
348
*/
349
350
/*!
351
\fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::push_back(T &&t)
352
\overload push_back
353
\since 5.9
354
355
\note Unlike the lvalue overload of push_back(), passing a reference to
356
an object that is already an element of \c *this leads to undefined
357
behavior:
358
359
\code
360
vla.push_back(std::move(vla[0])); // BUG: passing an object that is already in the container
361
\endcode
362
*/
363
364
/*!
365
\fn template<class T, qsizetype Prealloc> inline void QVarLengthArray<T, Prealloc>::removeLast()
366
\since 4.5
367
368
Decreases the size of the array by one. The allocated size is not changed.
369
370
\sa append()
371
*/
372
373
/*!
374
\fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::pop_back()
375
\since 5.0
376
377
Same as removeLast(). Provided for STL-compatibility.
378
*/
379
380
/*!
381
\fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::append(const T *buf, qsizetype size)
382
383
Appends \a size amount of items referenced by \a buf to this array.
384
*/
385
386
387
/*! \fn template<class T, qsizetype Prealloc> T *QVarLengthArray<T, Prealloc>::data()
388
389
Returns a pointer to the data stored in the array. The pointer can
390
be used to access and modify the items in the array.
391
392
Example:
393
\snippet code/doc_src_qvarlengtharray.cpp 3
394
395
The pointer remains valid as long as the array isn't reallocated.
396
397
This function is mostly useful to pass an array to a function
398
that accepts a plain C++ array.
399
400
\sa constData(), operator[]()
401
*/
402
403
/*! \fn template<class T, qsizetype Prealloc> const T *QVarLengthArray<T, Prealloc>::data() const
404
405
\overload
406
*/
407
408
/*! \fn template<class T, qsizetype Prealloc> const T *QVarLengthArray<T, Prealloc>::constData() const
409
410
Returns a const pointer to the data stored in the array. The
411
pointer can be used to access the items in the array. The
412
pointer remains valid as long as the array isn't reallocated.
413
414
This function is mostly useful to pass an array to a function
415
that accepts a plain C++ array.
416
417
\sa data(), operator[]()
418
*/
419
420
/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc> &QVarLengthArray<T, Prealloc>::operator=(const QVarLengthArray<T, Prealloc> &other)
421
Assigns \a other to this array and returns a reference to this array.
422
*/
423
424
/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc> &QVarLengthArray<T, Prealloc>::operator=(QVarLengthArray<T, Prealloc> &&other)
425
Move-assigns \a other to this array and returns a reference to this array.
426
After the move, \a other is empty.
427
\since 6.0
428
*/
429
430
/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc> &QVarLengthArray<T, Prealloc>::operator=(std::initializer_list<T> list)
431
\since 5.5
432
433
Assigns the values of \a list to this array, and returns a reference to this array.
434
*/
435
436
/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::QVarLengthArray(const QVarLengthArray<T, Prealloc> &other)
437
Constructs a copy of \a other.
438
*/
439
440
/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::QVarLengthArray(QVarLengthArray<T, Prealloc> &&other)
441
Move-constructs this variable-length array from \a other. After the move, \a other is empty.
442
\since 6.0
443
*/
444
445
/*! \fn template<class T, qsizetype Prealloc> const T &QVarLengthArray<T, Prealloc>::at(qsizetype i) const
446
447
Returns a reference to the item at index position \a i.
448
449
\a i must be a valid index position in the array (i.e., 0 <= \a i
450
< size()).
451
452
\sa value(), operator[]()
453
*/
454
455
/*! \fn template<class T, qsizetype Prealloc> T QVarLengthArray<T, Prealloc>::value(qsizetype i) const
456
457
Returns the value at index position \a i.
458
459
If the index \a i is out of bounds, the function returns
460
a \l{default-constructed value}. If you are certain that
461
\a i is within bounds, you can use at() instead, which is slightly
462
faster.
463
464
\sa at(), operator[]()
465
*/
466
467
/*! \fn template<class T, qsizetype Prealloc> T QVarLengthArray<T, Prealloc>::value(qsizetype i, const T &defaultValue) const
468
469
\overload
470
471
If the index \a i is out of bounds, the function returns
472
\a defaultValue.
473
*/
474
475
/*
476
\var QVarLengthArray::PreallocatedSize
477
\since 6.8
478
479
The same value as the \c{Prealloc} template argument. Provided for easier
480
access compared to manually extracting the value from the template
481
argument.
482
*/
483
484
/*!
485
\typedef QVarLengthArray::size_type
486
\since 4.7
487
488
Typedef for int. Provided for STL compatibility.
489
*/
490
491
/*!
492
\typedef QVarLengthArray::value_type
493
\since 4.7
494
495
Typedef for T. Provided for STL compatibility.
496
*/
497
498
/*!
499
\typedef QVarLengthArray::difference_type
500
\since 4.7
501
502
Typedef for ptrdiff_t. Provided for STL compatibility.
503
*/
504
505
/*!
506
\typedef QVarLengthArray::pointer
507
\since 4.7
508
509
Typedef for T *. Provided for STL compatibility.
510
*/
511
512
/*!
513
\typedef QVarLengthArray::const_pointer
514
\since 4.7
515
516
Typedef for const T *. Provided for STL compatibility.
517
*/
518
519
/*!
520
\typedef QVarLengthArray::reference
521
\since 4.7
522
523
Typedef for T &. Provided for STL compatibility.
524
*/
525
526
/*!
527
\typedef QVarLengthArray::const_reference
528
\since 4.7
529
530
Typedef for const T &. Provided for STL compatibility.
531
*/
532
533
/*!
534
\typedef QVarLengthArray::const_iterator
535
\since 4.7
536
537
Typedef for const T *. Provided for STL compatibility.
538
*/
539
540
/*!
541
\typedef QVarLengthArray::iterator
542
\since 4.7
543
544
Typedef for T *. Provided for STL compatibility.
545
*/
546
547
/*!
548
\typedef QVarLengthArray::const_reverse_iterator
549
\since 5.6
550
551
Typedef for \c{std::reverse_iterator<const T*>}. Provided for STL compatibility.
552
*/
553
554
/*!
555
\typedef QVarLengthArray::reverse_iterator
556
\since 5.6
557
558
Typedef for \c{std::reverse_iterator<T*>}. Provided for STL compatibility.
559
*/
560
561
/*!
562
\fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::prepend(const T &value)
563
\fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::prepend(T &&value)
564
565
\since 4.8
566
\deprecated [6.3] This is slow. If you must, use \c{insert(cbegin(), ~~~)} instead.
567
568
Inserts \a value at the beginning of the array.
569
570
571
This is the same as vector.insert(0, \a value).
572
573
For large arrays, this operation can be slow (\l{linear time}),
574
because it requires moving all the items in the vector by one
575
position further in memory. If you want a container class that
576
provides a fast prepend() function, use std::list instead.
577
578
\sa append(), insert()
579
*/
580
581
/*! \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::replace(qsizetype i, const T &value)
582
583
\since 4.8
584
Replaces the item at index position \a i with \a value.
585
586
\a i must be a valid index position in the array (i.e., 0 <= \a
587
i < size()).
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 middle of the array, starting at
598
index position \a i.
599
600
\sa insert(), replace()
601
*/
602
603
/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::iterator QVarLengthArray<T, Prealloc>::begin()
604
\since 4.8
605
606
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first item in
607
the array.
608
609
\sa constBegin(), end()
610
*/
611
612
/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::const_iterator QVarLengthArray<T, Prealloc>::begin() const
613
\since 4.8
614
\overload
615
*/
616
617
/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::const_iterator QVarLengthArray<T, Prealloc>::cbegin() const
618
\since 5.0
619
620
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item
621
in the array.
622
623
\sa begin(), cend()
624
*/
625
626
/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::const_iterator QVarLengthArray<T, Prealloc>::constBegin() const
627
\since 4.8
628
629
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item
630
in the array.
631
632
\sa begin(), constEnd()
633
*/
634
635
/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::iterator QVarLengthArray<T, Prealloc>::end()
636
\since 4.8
637
638
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item
639
after the last item in the array.
640
641
\sa begin(), constEnd()
642
*/
643
644
/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::const_iterator QVarLengthArray<T, Prealloc>::end() const
645
\since 4.8
646
647
\overload
648
*/
649
650
/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::const_iterator QVarLengthArray<T, Prealloc>::cend() const
651
\since 5.0
652
653
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary
654
item after the last item in the array.
655
656
\sa cbegin(), end()
657
*/
658
659
/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::const_iterator QVarLengthArray<T, Prealloc>::constEnd() const
660
\since 4.8
661
662
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary
663
item after the last item in the array.
664
665
\sa constBegin(), end()
666
*/
667
668
/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::reverse_iterator QVarLengthArray<T, Prealloc>::rbegin()
669
\since 5.6
670
671
Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to the first
672
item in the variable length array, in reverse order.
673
674
\sa begin(), crbegin(), rend()
675
*/
676
677
/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::const_reverse_iterator QVarLengthArray<T, Prealloc>::rbegin() const
678
\since 5.6
679
\overload
680
*/
681
682
/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::const_reverse_iterator QVarLengthArray<T, Prealloc>::crbegin() const
683
\since 5.6
684
685
Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing to the first
686
item in the variable length array, in reverse order.
687
688
\sa begin(), rbegin(), rend()
689
*/
690
691
/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::reverse_iterator QVarLengthArray<T, Prealloc>::rend()
692
\since 5.6
693
694
Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to one past
695
the last item in the variable length array, in reverse order.
696
697
\sa end(), crend(), rbegin()
698
*/
699
700
/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::const_reverse_iterator QVarLengthArray<T, Prealloc>::rend() const
701
\since 5.6
702
\overload
703
*/
704
705
/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::const_reverse_iterator QVarLengthArray<T, Prealloc>::crend() const
706
\since 5.6
707
708
Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing to one
709
past the last item in the variable length array, in reverse order.
710
711
\sa end(), rend(), rbegin()
712
*/
713
714
/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::iterator QVarLengthArray<T, Prealloc>::erase(const_iterator pos)
715
\since 4.8
716
717
Removes the item pointed to by the iterator \a pos from the
718
vector, and returns an iterator to the next item in the vector
719
(which may be end()).
720
721
\sa insert(), remove()
722
*/
723
724
/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::iterator QVarLengthArray<T, Prealloc>::erase(const_iterator begin, const_iterator end)
725
726
\overload
727
\since 4.8
728
729
Removes all the items from \a begin up to (but not including) \a
730
end. Returns an iterator to the same item that \a end referred to
731
before the call.
732
*/
733
734
/*!
735
\fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::insert(qsizetype i, const T &value)
736
\fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::insert(qsizetype i, T &&value)
737
\since 4.8
738
739
Inserts \a value at index position \a i in the array. If \a i is
740
0, the value is prepended to the vector. If \a i is size(), the
741
value is appended to the vector.
742
743
For large arrays, this operation can be slow (\l{linear time}),
744
because it requires moving all the items at indexes \a i and
745
above by one position further in memory. If you want a container
746
class that provides a fast insert() function, use std::list
747
instead.
748
749
\sa remove()
750
*/
751
752
/*! \fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::insert(qsizetype i, qsizetype count, const T &value)
753
754
\overload
755
\since 4.8
756
757
Inserts \a count copies of \a value at index position \a i in the
758
vector.
759
*/
760
761
/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::iterator QVarLengthArray<T, Prealloc>::insert(const_iterator before, const T &value)
762
\fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::iterator QVarLengthArray<T, Prealloc>::insert(const_iterator before, T &&value)
763
764
\overload
765
\since 4.8
766
767
Inserts \a value in front of the item pointed to by the iterator
768
\a before. Returns an iterator pointing at the inserted item.
769
*/
770
771
/*!
772
\fn template <class T, qsizetype Prealloc> template <typename...Args> QVarLengthArray<T, Prealloc>::iterator QVarLengthArray<T, Prealloc>::emplace(const_iterator pos, Args &&...args)
773
774
\since 6.3
775
776
Inserts an item in front of the item pointed to by the iterator
777
\a pos, passing \a args to its constructor.
778
779
Returns an iterator pointing at the emplaced item.
780
*/
781
782
/*!
783
\fn template <class T, qsizetype Prealloc> template <typename...Args> T &QVarLengthArray<T, Prealloc>::emplace_back(Args &&...args)
784
\since 6.3
785
786
Inserts an item at the back of this QVarLengthArray, passing
787
\a args to its constructor.
788
789
Returns a reference to the emplaced item.
790
*/
791
792
/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::iterator QVarLengthArray<T, Prealloc>::insert(const_iterator before, qsizetype count, const T &value)
793
794
\since 4.8
795
Inserts \a count copies of \a value in front of the item pointed to
796
by the iterator \a before. Returns an iterator pointing at the
797
first of the inserted items.
798
*/
799
800
801
802
/*! \fn template<class T, qsizetype Prealloc1, qsizetype Prealloc2> bool operator==(const QVarLengthArray<T, Prealloc1> &left, const QVarLengthArray<T, Prealloc2> &right)
803
804
\relates QVarLengthArray
805
\since 4.8
806
Returns \c true if the two arrays, specified by \a left and \a right, are
807
equal. The preallocation sizes \a Prealloc1 and \a Prealloc2 may differ.
808
809
Two arrays are considered equal if they contain the same values
810
in the same order.
811
812
This function requires the value type to have an implementation
813
of \c operator==().
814
815
\sa {operator!=(const QVarLengthArray<T, Prealloc1> &left, const QVarLengthArray<T, Prealloc2> &right)}{operator!=()}
816
*/
817
818
/*! \fn template<typename T, qsizetype Prealloc1, qsizetype Prealloc2> bool operator!=(const QVarLengthArray<T, Prealloc1> &left, const QVarLengthArray<T, Prealloc2> &right)
819
820
\relates QVarLengthArray
821
\since 4.8
822
Returns \c true if the two arrays, specified by \a left and \a right, are
823
\e not equal. The preallocation sizes \a Prealloc1 and \a Prealloc2 may
824
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> &lhs, const QVarLengthArray<T,Prealloc2> &rhs)
836
\since 5.6
837
\relates QVarLengthArray
838
839
Returns \c true if variable length array \a lhs is
840
\l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare}
841
{lexicographically less than} \a rhs; otherwise returns \c false. The
842
preallocation sizes \a Prealloc1 and \a Prealloc2 may differ.
843
844
This function requires the value type to have an implementation
845
of \c operator<().
846
*/
847
848
/*! \fn template<typename T, qsizetype Prealloc1, qsizetype Prealloc2> bool operator<=(const QVarLengthArray<T,Prealloc1> &lhs, const QVarLengthArray<T,Prealloc2> &rhs)
849
\since 5.6
850
\relates QVarLengthArray
851
852
Returns \c true if variable length array \a lhs is
853
\l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare}
854
{lexicographically less than or equal to} \a rhs; otherwise returns
855
\c false. The preallocation sizes \a Prealloc1 and \a Prealloc2 may differ.
856
857
This function requires the value type to have an implementation
858
of \c operator<().
859
*/
860
861
/*! \fn template<typename T, qsizetype Prealloc1, qsizetype Prealloc2> bool operator>(const QVarLengthArray<T,Prealloc1> &lhs, const QVarLengthArray<T,Prealloc2> &rhs)
862
\since 5.6
863
\relates QVarLengthArray
864
865
Returns \c true if variable length array \a lhs is
866
\l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare}
867
{lexicographically greater than} \a rhs; otherwise returns \c false. The
868
preallocation sizes \a Prealloc1 and \a Prealloc2 may differ.
869
870
This function requires the value type to have an implementation
871
of \c operator<().
872
*/
873
874
/*! \fn template<typename T, qsizetype Prealloc1, qsizetype Prealloc2> bool operator>=(const QVarLengthArray<T,Prealloc1> &lhs, const QVarLengthArray<T,Prealloc2> &rhs)
875
\since 5.6
876
\relates QVarLengthArray
877
878
Returns \c true if variable length array \a lhs is
879
\l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare}
880
{lexicographically greater than or equal to} \a rhs; otherwise returns
881
\c false. The preallocation sizes \a Prealloc1 and \a Prealloc2 may differ.
882
883
This function requires the value type to have an implementation
884
of \c operator<().
885
*/
886
887
/*! \fn template<typename T, qsizetype Prealloc1, qsizetype Prealloc2> auto operator<=>(const QVarLengthArray<T,Prealloc1> &lhs, const QVarLengthArray<T,Prealloc2> &rhs)
888
\since 6.9
889
\relates QVarLengthArray
890
891
Compares the contents of \a lhs and \a rhs
892
\l {https://en.cppreference.com/w/cpp/algorithm/lexicographical_compare_three_way}
893
{lexicographically}. The preallocation sizes \a Prealloc1 and \a Prealloc2 may
894
differ. Returns the result of the strongest applicable category type, that is
895
\c {decltype(lhs[0] <=> rhs[0])} if \c {operator<=>()} is available for type
896
\c {T}; otherwise \c {std::weak_ordering}.
897
898
\note This operator is only available in C++20 mode, and when the underlying
899
type \c T models the \c {std::three_way_comparable} concept
900
or provides \c {operator<()}.
901
*/
902
903
/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc> &QVarLengthArray<T, Prealloc>::operator<<(const T &value)
904
905
\since 4.8
906
Appends \a value to the array and returns a reference to this
907
vector.
908
909
\sa append(), operator+=()
910
*/
911
912
/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc> &QVarLengthArray<T, Prealloc>::operator<<(T &&value)
913
\since 5.11
914
915
\overload
916
917
\sa append(), 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 vector.
924
925
\sa append(), operator<<()
926
*/
927
928
/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc> &QVarLengthArray<T, Prealloc>::operator+=(T &&value)
929
\since 5.11
930
931
\overload
932
933
\sa append(), operator<<()
934
*/
935
936
/*! \fn template<class T, qsizetype Prealloc> template <typename AT = T> qsizetype QVarLengthArray<T, Prealloc>::indexOf(const AT &value, qsizetype from = 0) const
937
938
\since 5.3
939
Returns the index position of the first occurrence of \a value in
940
the array, searching forward from index position \a from.
941
Returns -1 if no item matched.
942
943
This function requires the value type to have an implementation of
944
\c operator==().
945
946
\sa lastIndexOf(), contains()
947
*/
948
949
/*! \fn template<class T, qsizetype Prealloc> template <typename AT = T> qsizetype QVarLengthArray<T, Prealloc>::lastIndexOf(const AT &value, qsizetype from = -1) const
950
951
\since 5.3
952
Returns the index position of the last occurrence of the value \a
953
value in the array, searching backward from index position \a
954
from. If \a from is -1 (the default), the search starts at the
955
last item. Returns -1 if no item matched.
956
957
This function requires the value type to have an implementation of
958
\c operator==().
959
960
\sa indexOf(), contains()
961
*/
962
963
/*! \fn template<class T, qsizetype Prealloc> template <typename AT = T> bool QVarLengthArray<T, Prealloc>::contains(const AT &value) const
964
965
\since 5.3
966
Returns \c true if the array contains an occurrence of \a value;
967
otherwise returns \c false.
968
969
This function requires the value type to have an implementation of
970
\c operator==().
971
972
\sa indexOf(), lastIndexOf()
973
*/
974
975
/*!
976
\fn template <typename T, qsizetype Prealloc> size_t qHash(const QVarLengthArray<T, Prealloc> &key, size_t seed = 0)
977
\qhasholdT{QVarLengthArray}{T}
978
\since 5.14
979
980
Returns the hash value for the \a key, using \a seed to seed the
981
calculation. The preallocation size \a Prealloc does not affect the hash.
982
*/
983
984
/*! \fn template <typename T, qsizetype Prealloc> template <typename AT = T> qsizetype QVarLengthArray<T, Prealloc>::removeAll(const AT &t)
985
\since 6.1
986
987
Removes all elements that compare equal to \a t from the
988
array. Returns the number of elements removed, if any.
989
990
\sa removeOne()
991
*/
992
993
/*! \fn template <typename T, qsizetype Prealloc> template <typename AT = T> bool QVarLengthArray<T, Prealloc>::removeOne(const AT &t)
994
\since 6.1
995
996
Removes the first element that compares equal to \a t from the
997
array. Returns whether an element was, in fact, removed.
998
999
\sa removeAll()
1000
*/
1001
1002
/*! \fn template <typename T, qsizetype Prealloc> template <typename Predicate> qsizetype QVarLengthArray<T, Prealloc>::removeIf(Predicate pred)
1003
\since 6.1
1004
1005
Removes all elements for which the predicate \a pred returns true
1006
from the array. Returns the number of elements removed, if any.
1007
1008
\sa removeAll()
1009
*/
1010
1011
/*! \fn template <typename T, qsizetype Prealloc, typename AT> qsizetype erase(QVarLengthArray<T, Prealloc> &array, const AT &t)
1012
\relates QVarLengthArray
1013
\since 6.1
1014
1015
Removes all elements that compare equal to \a t from the
1016
array \a array. Returns the number of elements removed, if any.
1017
1018
\note \a t is not allowed to be a reference to an element inside \a
1019
array. If you cannot be sure that this is not the case, take a copy
1020
of \a t and call this function with the copy.
1021
1022
\sa erase_if()
1023
*/
1024
1025
/*! \fn template <typename T, qsizetype Prealloc, typename Predicate> qsizetype erase_if(QVarLengthArray<T, Prealloc> &array, Predicate pred)
1026
\relates QVarLengthArray
1027
\since 6.1
1028
1029
Removes all elements for which the predicate \a pred returns true
1030
from the list \a array. Returns the number of elements removed, if
1031
any. The preallocation size \a Prealloc does not affect the operation.
1032
1033
\sa erase()
1034
*/
1035
1036
/*! \fn template <class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>& QVarLengthArray<T, Prealloc>::assign(qsizetype n, const T &t)
1037
\since 6.6
1038
1039
Replaces the contents of this container with \a n copies of \a t.
1040
1041
The size of this container will be equal to \a n. This function will only
1042
allocate memory if \a n exceeds the capacity of the container.
1043
*/
1044
1045
/*! \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)
1046
\since 6.6
1047
1048
Replaces the contents of this container with a copy of the elements in the
1049
iterator range [\a first, \a last).
1050
1051
The size of this container will be equal to the number of elements in the
1052
range [\a first, \a last). This function will only allocate memory if the
1053
number of elements in the range exceeds the capacity of the container.
1054
1055
The behavior is undefined if either argument is an iterator into *this.
1056
1057
\constraints
1058
\c InputIterator meets the requirements of an
1059
\l {https://en.cppreference.com/w/cpp/named_req/InputIterator} {LegacyInputIterator}.
1060
*/
1061
1062
/*! \fn template <class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>& QVarLengthArray<T, Prealloc>::assign(std::initializer_list<T> list)
1063
\since 6.6
1064
1065
Replaces the contents of this container with a copy of the elements of \a list.
1066
1067
The size of this container will be equal to the number of elements in \a list.
1068
1069
This function only allocates memory if the number of elements in \a list
1070
exceeds the capacity of the container.
1071
*/
qtbase
src
corelib
tools
qvarlengtharray.qdoc
Generated on
for Qt by
1.16.1