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
qlist.qdoc
Go to the documentation of this file.
1
// Copyright (C) 2020 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4
/*!
5
\class QVector
6
\inmodule QtCore
7
\brief QVector is an alias for QList.
8
9
QVector<T> is a template class where \a T specifies the element type.
10
11
Please see the QList documentation for details.
12
*/
13
14
/*!
15
\class QList
16
\inmodule QtCore
17
\brief The QList class is a template class that provides a dynamic array.
18
\ingroup containers
19
20
\ingroup tools
21
\ingroup shared
22
23
\reentrant
24
25
QList<T> is one of Qt's generic \l{container classes}, where \a T
26
specifies the type of elements stored in the list. It stores its items
27
in adjacent memory locations and provides fast index-based access. QVector<T> used to be a different class in
28
Qt 5, but is now a simple alias to QList.
29
30
QList<T> and QVarLengthArray<T>
31
provide similar APIs and functionality. They are often interchangeable,
32
but there are performance consequences. Here is an overview of use cases:
33
34
\list
35
\li QList should be your default first choice.
36
\li QVarLengthArray provides an array that reserves space on the stack,
37
but can dynamically grow onto the heap if required. It's good to
38
use for short lived containers that are usually small.
39
\li If you need a real linked list, which guarantees
40
\l{Algorithmic Complexity}{constant time} insertions mid-list and
41
uses iterators to items rather than indexes, use std::list.
42
\endlist
43
44
\note QList and QVarLengthArray both guarantee C-compatible
45
array layout.
46
\note QList in Qt 5 did not always have a C-compatible array layout and
47
we often recommended to use QVector instead for more predictable
48
performance. This is not the case in Qt 6 anymore, where both classes
49
now share an implementation and can be used interchangeably.
50
51
Here's an example of a QList that stores integers and a QList
52
that stores QString values:
53
54
\snippet code/src_corelib_tools_qlist.cpp 0
55
56
QList stores its items in an array of continuous memory. Typically, lists
57
are created with an initial size. For example, the following code
58
constructs a QList with 200 elements:
59
60
\snippet code/src_corelib_tools_qlist.cpp 1
61
62
The elements are automatically initialized with a
63
\l{default-constructed value}. If you want to initialize the
64
list with a different value, pass that value as the second
65
argument to the constructor:
66
67
\snippet code/src_corelib_tools_qlist.cpp 2
68
69
You can also call fill() at any time to fill the list with a
70
value.
71
72
QList uses 0-based indexes, just like C++ arrays. To access the
73
item at a particular index position, you can use operator[](). On
74
non-const lists, operator[]() returns a reference to the item
75
that can be used on the left side of an assignment:
76
77
\snippet code/src_corelib_tools_qlist.cpp 3
78
79
For read-only access, an alternative syntax is to use at():
80
81
\snippet code/src_corelib_tools_qlist.cpp 4
82
83
at() can be faster than operator[](), because it never causes a
84
\l{deep copy} to occur.
85
86
Another way to access the data stored in a QList is to call
87
data(). The function returns a pointer to the first item in the
88
list. You can use the pointer to directly access and modify the
89
elements stored in the list. The pointer is also useful if you
90
need to pass a QList to a function that accepts a plain C++
91
array.
92
93
If you want to find all occurrences of a particular value in a
94
list, use indexOf() or lastIndexOf(). The former searches
95
forward starting from a given index position, the latter searches
96
backward. Both return the index of the matching item if they found
97
one; otherwise, they return -1. For example:
98
99
\snippet code/src_corelib_tools_qlist.cpp 5
100
101
If you simply want to check whether a list contains a
102
particular value, use contains(). If you want to find out how
103
many times a particular value occurs in the list, use count().
104
105
QList provides these basic functions to add, move, and remove
106
items: insert(), replace(), remove(), prepend(), append(). With the
107
exception of append(), prepend() and replace(), these functions can be slow
108
(\l{linear time}) for large lists, because they require moving many items in
109
the list by one position in memory. If you want a container class that
110
provides fast insertion/removal in the middle, use std::list instead.
111
112
Unlike plain C++ arrays, QLists can be resized at any time by
113
calling resize(). If the new size is larger than the old size,
114
QList might need to reallocate the whole list. QList tries
115
to reduce the number of reallocations by preallocating up to twice
116
as much memory as the actual data needs.
117
118
If you're building a QList gradually and know in advance
119
approximately how many elements it will contain, you can call reserve(),
120
asking QList to preallocate a certain amount of memory.
121
You can also call capacity() to find out how much memory the
122
QList actually has allocated.
123
124
Note that using non-const operators and functions can cause QList
125
to do a deep copy of the data, due to \l{implicit sharing}.
126
127
QList's value type must be an \l{assignable data type}. This
128
covers most data types that are commonly used, but the compiler
129
won't let you, for example, store a QWidget as a value; instead,
130
store a QWidget *. A few functions have additional requirements;
131
for example, indexOf() and lastIndexOf() expect the value type to
132
support \c operator==(). These requirements are documented on a
133
per-function basis.
134
135
For iterating over the items, see \l {Iterating over Containers}.
136
For using QList with functions from \c {<algorithm>} header, such as
137
\c {std::sort()}, \c {std::reverse()}, and \c {std::count_if()},
138
see \l {Qt containers and std algorithms}.
139
For using QList with Qt's own generic algorithms such as \l{qJoin()} and
140
\l{qDeleteAll()}, see \l{<QtAlgorithms>}.
141
142
In addition to QList, Qt also provides QVarLengthArray, a very
143
low-level class with little functionality that is optimized for
144
speed.
145
146
\section2 More Information on Using Qt Containers
147
148
For a detailed discussion comparing Qt containers with each other and
149
with STL containers, see \l {Understand the Qt Containers}.
150
151
\section1 Maximum size and out-of-memory conditions
152
153
The maximum size of QList depends on the architecture. Most 64-bit
154
systems can allocate more than 2 GB of memory, with a typical limit
155
of 2^63 bytes. The actual value also depends on the overhead required for
156
managing the data block. As a result, you can expect the maximum size
157
of 2 GB minus overhead on 32-bit platforms, and 2^63 bytes minus overhead
158
on 64-bit platforms. The number of elements that can be stored in a
159
QList is this maximum size divided by the size of a stored element.
160
161
When memory allocation fails, QList uses the \l Q_CHECK_PTR macro,
162
which throws a \c std::bad_alloc exception if the application is being
163
compiled with exception support. If exceptions are disabled, then running
164
out of memory is undefined behavior.
165
166
Note that the operating system may impose further limits on applications
167
holding a lot of allocated memory, especially large, contiguous blocks.
168
Such considerations, the configuration of such behavior or any mitigation
169
are outside the scope of the Qt API.
170
*/
171
172
/*!
173
\fn template <typename T> QList<T> QList<T>::mid(qsizetype pos, qsizetype length = -1) const
174
175
Returns a sub-list which contains elements from this list,
176
starting at position \a pos. If \a length is -1 (the default), all
177
elements after \a pos are included; otherwise \a length elements (or
178
all remaining elements if there are less than \a length elements)
179
are included.
180
*/
181
182
/*!
183
\fn template <typename T> QList<T> QList<T>::first(qsizetype n) const
184
\since 6.0
185
186
Returns a sub-list that contains the first \a n elements
187
of this list.
188
189
\note The behavior is undefined when \a n < 0 or \a n > size().
190
191
\sa last(), sliced()
192
*/
193
194
/*!
195
\fn template <typename T> QList<T> QList<T>::last(qsizetype n) const
196
\since 6.0
197
198
Returns a sub-list that contains the last \a n elements of this list.
199
200
\note The behavior is undefined when \a n < 0 or \a n > size().
201
202
\sa first(), sliced()
203
*/
204
205
/*!
206
\fn template <typename T> QList<T> QList<T>::sliced(qsizetype pos, qsizetype n) const
207
\since 6.0
208
209
Returns a sub-list that contains \a n elements of this list,
210
starting at position \a pos.
211
212
\note The behavior is undefined when \a pos < 0, \a n < 0,
213
or \a pos + \a n > size().
214
215
\sa first(), last()
216
*/
217
218
/*!
219
\fn template <typename T> QList<T> QList<T>::sliced(qsizetype pos) const
220
\since 6.0
221
\overload
222
223
Returns a sub-list that contains the elements of this list starting at
224
position \a pos and extending to its end.
225
226
\note The behavior is undefined when \a pos < 0 or \a pos > size().
227
228
\sa first(), last()
229
*/
230
231
232
/*! \fn template <typename T> QList<T>::QList()
233
234
Constructs an empty list.
235
236
\sa resize()
237
*/
238
239
/*!
240
\fn template <typename T> QList<T>::QList(QList<T> &&other)
241
242
Move-constructs a QList instance, making it point at the same
243
object that \a other was pointing to.
244
245
\since 5.2
246
*/
247
248
/*! \fn template <typename T> QList<T>::QList(qsizetype size)
249
250
Constructs a list with an initial size of \a size elements.
251
252
The elements are initialized with a \l{default-constructed
253
value}.
254
255
\sa resize()
256
*/
257
258
/*! \fn template <typename T> QList<T>::QList(qsizetype size, Qt::Initialization)
259
\since 6.8
260
261
Constructs a list with an initial size of \a size elements.
262
263
QList will make an attempt at \b{not initializing} the elements.
264
265
//! [qlist-uninitialized-strategy]
266
Specifically:
267
268
\list
269
270
\li if \c{T} has a constructor that accepts \c{Qt::Uninitialized},
271
that constructor will be used to initialize the elements;
272
273
\li otherwise, each element is default constructed. For
274
trivially constructible types (such as \c{int}, \c{float}, etc.)
275
this is equivalent to not initializing them.
276
277
\endlist
278
//! [qlist-uninitialized-strategy]
279
280
\sa resizeForOverwrite()
281
*/
282
283
/*! \fn template <typename T> QList<T>::QList(qsizetype size, parameter_type value)
284
285
Constructs a list with an initial size of \a size elements.
286
Each element is initialized with \a value.
287
288
\sa resize(), fill()
289
*/
290
291
/*! \fn template <typename T> QList<T>::QList(const QList<T> &other)
292
293
Constructs a copy of \a other.
294
295
This operation takes \l{Algorithmic Complexity}{constant time},
296
because QList is \l{implicitly shared}. This makes returning
297
a QList from a function very fast. If a shared instance is
298
modified, it will be copied (copy-on-write), and that takes
299
\l{Algorithmic Complexity}{linear time}.
300
301
\sa operator=()
302
*/
303
304
/*! \fn template <typename T> QList<T>::QList(std::initializer_list<T> args)
305
\since 4.8
306
307
Constructs a list from the std::initializer_list given by \a args.
308
*/
309
310
/*! \fn template<typename T> template <typename InputIterator, QList<T>::if_input_iterator<InputIterator> = true> QList<T>::QList(InputIterator first, InputIterator last)
311
\since 5.14
312
313
Constructs a list with the contents in the iterator range [\a first, \a last).
314
315
The value type of \c InputIterator must be convertible to \c T.
316
317
\constraints
318
\c InputIterator meets the requirements of a
319
\l {https://en.cppreference.com/w/cpp/named_req/InputIterator} {LegacyInputIterator}.
320
*/
321
322
/*! \fn template <typename T> QList<T>::~QList()
323
324
Destroys the list.
325
*/
326
327
/*! \fn template <typename T> QList<T> &QList<T>::operator=(const QList<T> &other)
328
329
Assigns \a other to this list and returns a reference to this
330
list.
331
*/
332
333
/*!
334
\fn template <typename T> QList<T> &QList<T>::operator=(QList<T> &&other)
335
336
Move-assigns \a other to this QList instance.
337
338
\since 5.2
339
*/
340
341
/*!
342
\fn template <typename T> QList<T> &QList<T>::operator=(std::initializer_list<T> args)
343
\since 5.14
344
345
Assigns the collection of values in \a args to this QList instance.
346
*/
347
348
/*! \fn template <typename T> void QList<T>::swap(QList<T> &other)
349
\since 4.8
350
\memberswap{list}
351
*/
352
353
/*! \fn template <typename T> void QList<T>::swapItemsAt(qsizetype i, qsizetype j)
354
355
Exchange the item at index position \a i with the item at index
356
position \a j. This function assumes that both \a i and \a j are
357
at least 0 but less than size(). To avoid failure, test that both
358
\a i and \a j are at least 0 and less than size().
359
*/
360
361
362
/*! \fn template <typename T> bool QList<T>::operator==(const QList<T> &other) const
363
364
Returns \c true if \a other is equal to this list; otherwise
365
returns \c false.
366
367
Two lists are considered equal if they contain the same values
368
in the same order.
369
370
This function requires the value type to have an implementation
371
of \c operator==().
372
373
\sa operator!=()
374
*/
375
376
/*! \fn template <typename T> bool QList<T>::operator!=(const QList<T> &other) const
377
378
Returns \c true if \a other is not equal to this list; otherwise
379
returns \c false.
380
381
Two lists are considered equal if they contain the same values
382
in the same order.
383
384
This function requires the value type to have an implementation
385
of \c operator==().
386
387
\sa operator==()
388
*/
389
390
/*! \fn template <typename T> bool QList<T>::operator<(const QList<T> &other) const
391
\since 5.6
392
393
Returns \c true if this list is
394
\l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare}
395
{lexically less than} \a other; otherwise returns \c false.
396
397
This function requires the value type to have an implementation
398
of \c operator<().
399
*/
400
401
/*! \fn template <typename T> bool QList<T>::operator<=(const QList<T> &other) const
402
\since 5.6
403
404
Returns \c true if this list is
405
\l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare}
406
{lexically less than or equal to} \a other; otherwise returns \c false.
407
408
This function requires the value type to have an implementation
409
of \c operator<().
410
*/
411
412
/*! \fn template <typename T> bool QList<T>::operator>(const QList<T> &other) const
413
\since 5.6
414
415
Returns \c true if this list is
416
\l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare}
417
{lexically greater than} \a other; otherwise returns \c false.
418
419
This function requires the value type to have an implementation
420
of \c operator<().
421
*/
422
423
/*! \fn template <typename T> bool QList<T>::operator>=(const QList<T> &other) const
424
\since 5.6
425
426
Returns \c true if this list is
427
\l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare}
428
{lexically greater than or equal to} \a other; otherwise returns \c false.
429
430
This function requires the value type to have an implementation
431
of \c operator<().
432
*/
433
434
/*!
435
\fn template <typename T> auto QList<T>::operator<=>(const QList<T> &lhs, const QList<T> &rhs)
436
\since 6.9
437
438
Compares the contents of \a lhs and \a rhs
439
\l {https://en.cppreference.com/w/cpp/algorithm/lexicographical_compare_three_way}
440
{lexicographically}. Returns the result of the strongest applicable category
441
type, that is \c {decltype(lhs[0] <=> rhs[0])} if \c {operator<=>()} is
442
available for type \c {T}; otherwise \c {std::weak_ordering}.
443
444
\note This operator is only available in C++20 mode, and when the underlying
445
type \c T models the \c {std::three_way_comparable} concept
446
or provides \c {operator<()}.
447
*/
448
449
/*!
450
\fn template <typename T> size_t qHash(const QList<T> &key, size_t seed = 0)
451
\since 5.6
452
\qhasholdT{QList}{T}
453
*/
454
455
/*! \fn template <typename T> qsizetype QList<T>::size() const
456
457
Returns the number of items in the list.
458
459
\sa isEmpty(), resize()
460
*/
461
462
/*! \fn template <typename T> bool QList<T>::isEmpty() const
463
464
Returns \c true if the list has size 0; otherwise returns \c false.
465
466
\sa size(), resize()
467
*/
468
469
/*! \fn template <typename T> void QList<T>::resize(qsizetype size)
470
\fn template <typename T> void QList<T>::resize(qsizetype size, parameter_type c)
471
\since 6.0
472
473
Sets the size of the list to \a size. If \a size is greater than the
474
current size, elements are added to the end; the new elements are
475
initialized with either a \l{default-constructed value} or \a c. If \a size
476
is less than the current size, elements are removed from the end.
477
478
If this list is not shared, the capacity() is preserved. Use squeeze()
479
to shed excess capacity.
480
481
\note In Qt versions prior to 5.7 (for QVector; QList lacked a resize()
482
until 6.0), this function released the memory used by the list instead of
483
preserving the capacity.
484
485
\sa size()
486
*/
487
488
/*! \fn template <typename T> void QList<T>::resizeForOverwrite(qsizetype size)
489
\since 6.8
490
491
Sets the size of the list to \a size. If \a size is less than the
492
current size, elements are removed from the end. If \a size is
493
greater than the current size, elements are added to the end; QList
494
will make an attempt at \b{not initializing} these new elements.
495
496
\include qlist.qdoc qlist-uninitialized-strategy
497
*/
498
499
/*! \fn template <typename T> qsizetype QList<T>::capacity() const
500
501
Returns the maximum number of items that can be stored in the
502
list without forcing a reallocation.
503
504
The sole purpose of this function is to provide a means of fine
505
tuning QList's memory usage. In general, you will rarely ever
506
need to call this function. If you want to know how many items are
507
in the list, call size().
508
509
\note a statically allocated list will report a capacity of 0,
510
even if it's not empty.
511
512
\warning The free space position in the allocated memory block is undefined.
513
In other words, you should not assume that the free memory is always located
514
at the end of the list. You can call reserve() to ensure that there is
515
enough space at the end.
516
517
\sa reserve(), squeeze()
518
*/
519
520
/*! \fn template <typename T> void QList<T>::reserve(qsizetype size)
521
522
Attempts to allocate memory for at least \a size elements.
523
524
If you know in advance how large the list will be, you should call this
525
function to prevent reallocations and memory fragmentation. If you resize
526
the list often, you are also likely to get better performance.
527
528
If in doubt about how much space shall be needed, it is usually better to
529
use an upper bound as \a size, or a high estimate of the most likely size,
530
if a strict upper bound would be much bigger than this. If \a size is an
531
underestimate, the list will grow as needed once the reserved size is
532
exceeded, which may lead to a larger allocation than your best overestimate
533
would have and will slow the operation that triggers it.
534
535
\warning reserve() reserves memory but does not change the size of the
536
list. Accessing data beyond the current end of the list is
537
undefined behavior. If you need to access memory beyond the current end of
538
the list, use resize().
539
540
\sa squeeze(), capacity(), resize()
541
*/
542
543
/*! \fn template <typename T> void QList<T>::squeeze()
544
545
Releases any memory not required to store the items.
546
547
The sole purpose of this function is to provide a means of fine
548
tuning QList's memory usage. In general, you will rarely ever
549
need to call this function.
550
551
\sa reserve(), capacity()
552
*/
553
554
/*! \fn template <typename T> void QList<T>::detach()
555
556
Ensures that this QList's data is no longer
557
\l{Implicit Sharing}{shared} with other instances.
558
*/
559
560
/*! \fn template <typename T> bool QList<T>::isDetached() const
561
562
\internal
563
*/
564
565
/*! \fn template <typename T> void QList<T>::setSharable(bool sharable)
566
567
\internal
568
*/
569
570
/*! \fn template <typename T> bool QList<T>::isSharedWith(const QList<T> &other) const
571
572
\internal
573
*/
574
575
/*! \fn template <typename T> T *QList<T>::data()
576
577
Returns a pointer to the data stored in the list. The pointer
578
can be used to access and modify the items in the list.
579
580
Example:
581
\snippet code/src_corelib_tools_qlist.cpp 6
582
583
\warning The pointer is invalidated on detachment or when the QList is
584
modified.
585
586
This function is mostly useful to pass a list to a function
587
that accepts a plain C++ array.
588
589
\sa constData(), operator[]()
590
*/
591
592
/*! \fn template <typename T> const T *QList<T>::data() const
593
594
\overload
595
*/
596
597
/*! \fn template <typename T> const T *QList<T>::constData() const
598
599
Returns a const pointer to the data stored in the list. The
600
pointer can be used to access the items in the list.
601
602
\warning The pointer is invalidated on detachment or when the QList is
603
modified.
604
605
This function is mostly useful to pass a list to a function
606
that accepts a plain C++ array.
607
608
\sa data(), operator[]()
609
*/
610
611
/*! \fn template <typename T> void QList<T>::clear()
612
613
Removes all the elements from the list.
614
615
If this list is not shared, the capacity() is preserved. Use squeeze() to
616
shed excess capacity.
617
618
\note In Qt versions prior to 5.7 (for QVector) and 6.0 (for QList), this
619
function released the memory used by the list instead of preserving the
620
capacity.
621
622
\sa resize(), squeeze()
623
*/
624
625
/*! \fn template <typename T> const T &QList<T>::at(qsizetype i) const
626
627
Returns the item at index position \a i in the list.
628
629
\a i must be a valid index position in the list (i.e., 0 <= \a
630
i < size()).
631
632
\sa value(), operator[]()
633
*/
634
635
/*! \fn template <typename T> T &QList<T>::operator[](qsizetype i)
636
637
Returns the item at index position \a i as a modifiable reference.
638
639
\a i must be a valid index position in the list (i.e., 0 <= \a i
640
< size()).
641
642
Note that using non-const operators can cause QList to do a deep
643
copy.
644
645
\sa at(), value()
646
*/
647
648
/*! \fn template <typename T> const T &QList<T>::operator[](qsizetype i) const
649
650
\overload
651
652
Same as at(\a i).
653
*/
654
655
/*!
656
\fn template <typename T> void QList<T>::append(parameter_type value)
657
658
Inserts \a value at the end of the list.
659
660
Example:
661
\snippet code/src_corelib_tools_qlist.cpp 7
662
663
This is the same as calling resize(size() + 1) and assigning \a
664
value to the new last element in the list.
665
666
This operation is relatively fast, because QList typically
667
allocates more memory than necessary, so it can grow without
668
reallocating the entire list each time.
669
670
\sa operator<<(), prepend(), insert()
671
*/
672
673
/*!
674
\fn template <typename T> void QList<T>::append(rvalue_ref value)
675
\since 5.6
676
677
\overload
678
679
Example:
680
\snippet code/src_corelib_tools_qlist.cpp move-append
681
*/
682
683
/*! \fn template <typename T> void QList<T>::append(const QList<T> &value)
684
685
\overload
686
687
\since 5.5
688
689
Appends the items of the \a value list to this list.
690
691
\sa operator<<(), operator+=()
692
*/
693
694
/*! \fn template <typename T> void QList<T>::append(QList<T> &&value)
695
\overload
696
697
\since 6.0
698
699
Moves the items of the \a value list to the end of this list.
700
701
\sa operator<<(), operator+=()
702
*/
703
704
/*!
705
\fn template <typename T> void QList<T>::prepend(parameter_type value)
706
\fn template <typename T> void QList<T>::prepend(rvalue_ref value)
707
708
Inserts \a value at the beginning of the list.
709
710
Example:
711
\snippet code/src_corelib_tools_qlist.cpp 8
712
713
This is the same as list.insert(0, \a value).
714
715
Normally this operation is relatively fast (amortized \l{constant time}).
716
QList is able to allocate extra memory at the beginning of the list data
717
and grow in that direction without reallocating or moving the data on each
718
operation. However if you want a container class with a guarantee of
719
\l{constant time} prepend, use std::list instead,
720
but prefer QList otherwise.
721
722
\sa append(), insert()
723
*/
724
725
/*!
726
\fn template <typename T> template <typename ...Args> T &QList<T>::emplaceBack(Args&&... args)
727
\fn template <typename T> template <typename ...Args> T &QList<T>::emplace_back(Args&&... args)
728
729
Adds a new element to the end for the container. This new element
730
is constructed in-place using \a args as the arguments for its
731
construction.
732
733
Returns a reference to the new element.
734
735
Example:
736
\snippet code/src_corelib_tools_qlist.cpp emplace-back
737
738
It is also possible to access a newly created object by using
739
returned reference:
740
\snippet code/src_corelib_tools_qlist.cpp emplace-back-ref
741
742
This is the same as list.emplace(list.size(), \a args).
743
744
\sa emplace
745
*/
746
747
/*! \fn template <typename T> void QList<T>::insert(qsizetype i, parameter_type value)
748
\fn template <typename T> void QList<T>::insert(qsizetype i, rvalue_ref value)
749
750
Inserts \a value at index position \a i in the list. If \a i is
751
0, the value is prepended to the list. If \a i is size(), the
752
value is appended to the list.
753
754
Example:
755
\snippet code/src_corelib_tools_qlist.cpp 9
756
757
For large lists, this operation can be slow (\l{linear time}),
758
because it requires moving all the items at indexes \a i and
759
above by one position further in memory. If you want a container
760
class that provides a fast insert() function, use std::list
761
instead.
762
763
\sa append(), prepend(), remove()
764
*/
765
766
/*! \fn template <typename T> void QList<T>::insert(qsizetype i, qsizetype count, parameter_type value)
767
768
\overload
769
770
Inserts \a count copies of \a value at index position \a i in the
771
list.
772
773
Example:
774
\snippet code/src_corelib_tools_qlist.cpp 10
775
*/
776
777
/*! \fn template <typename T> QList<T>::iterator QList<T>::insert(const_iterator before, parameter_type value)
778
\fn template <typename T> QList<T>::iterator QList<T>::insert(const_iterator before, rvalue_ref value)
779
780
\overload
781
782
Inserts \a value in front of the item pointed to by the iterator
783
\a before. Returns an iterator pointing at the inserted item.
784
*/
785
786
/*! \fn template <typename T> QList<T>::iterator QList<T>::insert(const_iterator before, qsizetype count, parameter_type value)
787
788
Inserts \a count copies of \a value in front of the item pointed to
789
by the iterator \a before. Returns an iterator pointing at the
790
first of the inserted items.
791
*/
792
793
/*!
794
\fn template <typename T> template <typename ...Args> QList<T>::iterator QList<T>::emplace(qsizetype i, Args&&... args)
795
796
Extends the container by inserting a new element at position \a i.
797
This new element is constructed in-place using \a args as the
798
arguments for its construction.
799
800
Returns an iterator to the new element.
801
802
Example:
803
\snippet code/src_corelib_tools_qlist.cpp emplace
804
805
\note It is guaranteed that the element will be created in place
806
at the beginning, but after that it might be copied or
807
moved to the right position.
808
809
\sa emplaceBack
810
*/
811
812
813
/*! \fn template <typename T> void QList<T>::replace(qsizetype i, parameter_type value)
814
\fn template <typename T> void QList<T>::replace(qsizetype i, rvalue_ref value)
815
816
Replaces the item at index position \a i with \a value.
817
818
\a i must be a valid index position in the list (i.e., 0 <= \a
819
i < size()).
820
821
\sa operator[](), remove()
822
*/
823
824
/*! \fn template <typename T> void QList<T>::remove(qsizetype i, qsizetype n = 1)
825
826
Removes \a n elements from the list, starting at index position \a i.
827
828
//! [shrinking-erase]
829
Element removal will preserve the list's capacity and not reduce the amount of
830
allocated memory. To shed extra capacity and free as much memory as possible,
831
call squeeze().
832
//! [shrinking-erase]
833
834
//! [iterator-invalidation-erase]
835
\note When QList is not \l{implicitly shared}, this function only
836
invalidates iterators at or after the specified position.
837
//! [iterator-invalidation-erase]
838
839
\sa insert(), replace(), fill()
840
*/
841
842
/*! \fn template <typename T> void QList<T>::removeAt(qsizetype i)
843
\since 5.2
844
845
Removes the element at index position \a i.
846
Equivalent to
847
\code
848
remove(i);
849
\endcode
850
851
\include qlist.qdoc shrinking-erase
852
\include qlist.qdoc iterator-invalidation-erase
853
854
\sa remove()
855
*/
856
857
/*! \fn template <typename T> template <typename AT = T> qsizetype QList<T>::removeAll(const AT &t)
858
\since 5.4
859
860
Removes all elements that compare equal to \a t from the
861
list. Returns the number of elements removed, if any.
862
863
\include qlist.qdoc shrinking-erase
864
865
\sa removeOne()
866
*/
867
868
/*! \fn template <typename T> template <typename AT = T> bool QList<T>::removeOne(const AT &t)
869
\since 5.4
870
871
Removes the first element that compares equal to \a t from the
872
list. Returns whether an element was, in fact, removed.
873
874
\include qlist.qdoc shrinking-erase
875
876
\sa removeAll()
877
*/
878
879
/*! \fn template <typename T> template <typename Predicate> qsizetype QList<T>::removeIf(Predicate pred)
880
\since 6.1
881
882
Removes all elements for which the predicate \a pred returns true
883
from the list. Returns the number of elements removed, if any.
884
885
\sa removeAll()
886
*/
887
888
/*! \fn template <typename T> qsizetype QList<T>::length() const
889
\since 5.2
890
891
Same as size() and count().
892
893
\sa size(), count()
894
*/
895
896
/*! \fn template <typename T> T QList<T>::takeAt(qsizetype i)
897
\since 5.2
898
899
Removes the element at index position \a i and returns it.
900
901
Equivalent to
902
\code
903
T t = at(i);
904
remove(i);
905
return t;
906
\endcode
907
908
\include qlist.qdoc iterator-invalidation-erase
909
910
\sa takeFirst(), takeLast()
911
*/
912
913
/*! \fn template <typename T> void QList<T>::move(qsizetype from, qsizetype to)
914
\since 5.6
915
916
Moves the item at index position \a from to index position \a to.
917
918
\c from and \c to must be within bounds.
919
920
For example, to move the first item to the end of the list:
921
\code
922
QList<int> list = {1, 2, 3};
923
list.move(0, list.size() - 1);
924
qDebug() << list; // Prints "QList(2, 3, 1)"
925
\endcode
926
*/
927
928
/*! \fn template <typename T> void QList<T>::removeFirst()
929
\since 5.1
930
Removes the first item in the list. Calling this function is
931
equivalent to calling remove(0). The list must not be empty. If
932
the list can be empty, call isEmpty() before calling this
933
function.
934
935
\include qlist.qdoc shrinking-erase
936
937
\sa remove(), takeFirst(), isEmpty()
938
*/
939
940
/*! \fn template <typename T> void QList<T>::removeLast()
941
\since 5.1
942
Removes the last item in the list. Calling this function is
943
equivalent to calling remove(size() - 1). The list must not be
944
empty. If the list can be empty, call isEmpty() before calling
945
this function.
946
947
\include qlist.qdoc shrinking-erase
948
949
\sa remove(), takeLast(), removeFirst(), isEmpty()
950
*/
951
952
/*! \fn template <typename T> T QList<T>::takeFirst()
953
\since 5.1
954
955
Removes the first item in the list and returns it. This function
956
assumes the list is not empty. To avoid failure, call isEmpty()
957
before calling this function.
958
959
\sa takeLast(), removeFirst()
960
*/
961
962
/*! \fn template <typename T> T QList<T>::takeLast()
963
\since 5.1
964
965
Removes the last item in the list and returns it. This function
966
assumes the list is not empty. To avoid failure, call isEmpty()
967
before calling this function.
968
969
If you don't use the return value, removeLast() is more
970
efficient.
971
972
\sa takeFirst(), removeLast()
973
*/
974
975
/*!
976
\fn template <typename T> template <typename ...Args> QList<T>::iterator QList<T>::emplace(const_iterator before, Args&&... args)
977
978
\overload
979
980
Creates a new element in front of the item pointed to by the
981
iterator \a before. This new element is constructed in-place
982
using \a args as the arguments for its construction.
983
984
Returns an iterator to the new element.
985
*/
986
987
/*! \fn template <typename T> QList<T> &QList<T>::fill(parameter_type value, qsizetype size = -1)
988
989
Assigns \a value to all items in the list. If \a size is
990
different from -1 (the default), the list is resized to \a size beforehand.
991
992
Example:
993
\snippet code/src_corelib_tools_qlist.cpp 11
994
995
\sa resize()
996
*/
997
998
/*! \fn template <typename T> template <typename AT = T> qsizetype QList<T>::indexOf(const AT &value, qsizetype from = 0) const
999
1000
Returns the index position of the first occurrence of \a value in
1001
the list, searching forward from index position \a from.
1002
Returns -1 if no item matched.
1003
1004
Example:
1005
\snippet code/src_corelib_tools_qlist.cpp 12
1006
1007
This function requires the value type to have an implementation of
1008
\c operator==().
1009
1010
\sa lastIndexOf(), contains()
1011
*/
1012
1013
/*! \fn template <typename T> template <typename AT = T> qsizetype QList<T>::lastIndexOf(const AT &value, qsizetype from = -1) const
1014
1015
Returns the index position of the last occurrence of the value \a
1016
value in the list, searching backward from index position \a
1017
from. If \a from is -1 (the default), the search starts at the
1018
last item. Returns -1 if no item matched.
1019
1020
Example:
1021
\snippet code/src_corelib_tools_qlist.cpp 13
1022
1023
This function requires the value type to have an implementation of
1024
\c operator==().
1025
1026
\sa indexOf()
1027
*/
1028
1029
/*! \fn template <typename T> template <typename AT = T> bool QList<T>::contains(const AT &value) const
1030
1031
Returns \c true if the list contains an occurrence of \a value;
1032
otherwise returns \c false.
1033
1034
This function requires the value type to have an implementation of
1035
\c operator==().
1036
1037
\sa indexOf(), count()
1038
*/
1039
1040
/*! \fn template <typename T> bool QList<T>::startsWith(parameter_type value) const
1041
\since 4.5
1042
1043
Returns \c true if this list is not empty and its first
1044
item is equal to \a value; otherwise returns \c false.
1045
1046
\sa isEmpty(), first()
1047
*/
1048
1049
/*! \fn template <typename T> bool QList<T>::endsWith(parameter_type value) const
1050
\since 4.5
1051
1052
Returns \c true if this list is not empty and its last
1053
item is equal to \a value; otherwise returns \c false.
1054
1055
\sa isEmpty(), last()
1056
*/
1057
1058
1059
/*! \fn template <typename T> template <typename AT = T> qsizetype QList<T>::count(const AT &value) const
1060
1061
Returns the number of occurrences of \a value in the list.
1062
1063
This function requires the value type to have an implementation of
1064
\c operator==().
1065
1066
\sa contains(), indexOf()
1067
*/
1068
1069
/*! \fn template <typename T> qsizetype QList<T>::count() const
1070
1071
\overload
1072
1073
Same as size().
1074
*/
1075
1076
/*! \fn template <typename T> QList<T>::iterator QList<T>::begin()
1077
1078
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the
1079
first item in the list.
1080
1081
//! [iterator-invalidation-func-desc]
1082
\warning The returned iterator is invalidated on detachment or when the
1083
QList is modified.
1084
//! [iterator-invalidation-func-desc]
1085
1086
\sa constBegin(), end()
1087
*/
1088
1089
/*! \fn template <typename T> QList<T>::const_iterator QList<T>::begin() const
1090
1091
\overload
1092
*/
1093
1094
/*! \fn template <typename T> QList<T>::const_iterator QList<T>::cbegin() const
1095
\since 5.0
1096
1097
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the
1098
first item in the list.
1099
1100
\include qlist.qdoc iterator-invalidation-func-desc
1101
1102
\sa begin(), cend()
1103
*/
1104
1105
/*! \fn template <typename T> QList<T>::const_iterator QList<T>::constBegin() const
1106
1107
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the
1108
first item in the list.
1109
1110
\include qlist.qdoc iterator-invalidation-func-desc
1111
1112
\sa begin(), constEnd()
1113
*/
1114
1115
/*! \fn template <typename T> QList<T>::iterator QList<T>::end()
1116
1117
Returns an \l{STL-style iterators}{STL-style iterator} pointing just after
1118
the last item in the list.
1119
1120
\include qlist.qdoc iterator-invalidation-func-desc
1121
1122
\sa begin(), constEnd()
1123
*/
1124
1125
/*! \fn template <typename T> QList<T>::const_iterator QList<T>::end() const
1126
1127
\overload
1128
*/
1129
1130
/*! \fn template <typename T> QList<T>::const_iterator QList<T>::cend() const
1131
\since 5.0
1132
1133
Returns a const \l{STL-style iterators}{STL-style iterator} pointing just
1134
after the last item in the list.
1135
1136
\include qlist.qdoc iterator-invalidation-func-desc
1137
1138
\sa cbegin(), end()
1139
*/
1140
1141
/*! \fn template <typename T> QList<T>::const_iterator QList<T>::constEnd() const
1142
1143
Returns a const \l{STL-style iterators}{STL-style iterator} pointing just
1144
after the last item in the list.
1145
1146
\include qlist.qdoc iterator-invalidation-func-desc
1147
1148
\sa constBegin(), end()
1149
*/
1150
1151
/*! \fn template <typename T> QList<T>::reverse_iterator QList<T>::rbegin()
1152
\since 5.6
1153
1154
Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to
1155
the first item in the list, in reverse order.
1156
1157
\include qlist.qdoc iterator-invalidation-func-desc
1158
1159
\sa begin(), crbegin(), rend()
1160
*/
1161
1162
/*! \fn template <typename T> QList<T>::const_reverse_iterator QList<T>::rbegin() const
1163
\since 5.6
1164
\overload
1165
*/
1166
1167
/*! \fn template <typename T> QList<T>::const_reverse_iterator QList<T>::crbegin() const
1168
\since 5.6
1169
1170
Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing
1171
to the first item in the list, in reverse order.
1172
1173
\include qlist.qdoc iterator-invalidation-func-desc
1174
1175
\sa begin(), rbegin(), rend()
1176
*/
1177
1178
/*! \fn template <typename T> QList<T>::reverse_iterator QList<T>::rend()
1179
\since 5.6
1180
1181
Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing just
1182
after the last item in the list, in reverse order.
1183
1184
\include qlist.qdoc iterator-invalidation-func-desc
1185
1186
\sa end(), crend(), rbegin()
1187
*/
1188
1189
/*! \fn template <typename T> QList<T>::const_reverse_iterator QList<T>::rend() const
1190
\since 5.6
1191
\overload
1192
*/
1193
1194
/*! \fn template <typename T> QList<T>::const_reverse_iterator QList<T>::crend() const
1195
\since 5.6
1196
1197
Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing
1198
just after the last item in the list, in reverse order.
1199
1200
\include qlist.qdoc iterator-invalidation-func-desc
1201
1202
\sa end(), rend(), rbegin()
1203
*/
1204
1205
/*! \fn template <typename T> QList<T>::iterator QList<T>::erase(const_iterator pos)
1206
1207
Removes the item pointed to by the iterator \a pos from the
1208
list, and returns an iterator to the next item in the list
1209
(which may be end()).
1210
1211
\include qlist.qdoc shrinking-erase
1212
\include qlist.qdoc iterator-invalidation-erase
1213
1214
\sa insert(), remove()
1215
*/
1216
1217
/*! \fn template <typename T> QList<T>::iterator QList<T>::erase(const_iterator begin, const_iterator end)
1218
1219
\overload
1220
1221
Removes all the items from \a begin up to (but not including) \a
1222
end. Returns an iterator to the same item that \a end referred to
1223
before the call.
1224
1225
\include qlist.qdoc shrinking-erase
1226
\include qlist.qdoc iterator-invalidation-erase
1227
*/
1228
1229
/*! \fn template <typename T> T& QList<T>::first()
1230
1231
Returns a reference to the first item in the list. This
1232
function assumes that the list isn't empty.
1233
1234
\sa last(), isEmpty(), constFirst()
1235
*/
1236
1237
/*! \fn template <typename T> const T& QList<T>::first() const
1238
1239
\overload
1240
*/
1241
1242
/*! \fn template <typename T> const T& QList<T>::constFirst() const
1243
\since 5.6
1244
1245
Returns a const reference to the first item in the list. This
1246
function assumes that the list isn't empty.
1247
1248
\sa constLast(), isEmpty(), first()
1249
*/
1250
1251
/*! \fn template <typename T> T& QList<T>::last()
1252
1253
Returns a reference to the last item in the list. This function
1254
assumes that the list isn't empty.
1255
1256
\sa first(), isEmpty(), constLast()
1257
*/
1258
1259
/*! \fn template <typename T> const T& QList<T>::last() const
1260
1261
\overload
1262
*/
1263
1264
/*! \fn template <typename T> const T& QList<T>::constLast() const
1265
\since 5.6
1266
1267
Returns a const reference to the last item in the list. This function
1268
assumes that the list isn't empty.
1269
1270
\sa constFirst(), isEmpty(), last()
1271
*/
1272
1273
/*! \fn template <typename T> T QList<T>::value(qsizetype i) const
1274
1275
Returns the value at index position \a i in the list.
1276
1277
If the index \a i is out of bounds, the function returns a
1278
\l{default-constructed value}. If you are certain that \a i is within
1279
bounds, you can use at() instead, which is slightly faster.
1280
1281
\sa at(), operator[]()
1282
*/
1283
1284
/*! \fn template <typename T> T QList<T>::value(qsizetype i, parameter_type defaultValue) const
1285
1286
\overload
1287
1288
If the index \a i is out of bounds, the function returns \a defaultValue.
1289
*/
1290
1291
/*! \fn template <typename T> void QList<T>::push_back(parameter_type value)
1292
1293
This function is provided for STL compatibility. It is equivalent
1294
to append(\a value).
1295
*/
1296
1297
/*! \fn template <typename T> void QList<T>::push_back(rvalue_ref value)
1298
\since 5.6
1299
\overload
1300
*/
1301
1302
/*!
1303
\fn template <typename T> void QList<T>::push_front(parameter_type value)
1304
\fn template <typename T> void QList<T>::push_front(rvalue_ref value)
1305
1306
This function is provided for STL compatibility. It is equivalent
1307
to prepend(\a value).
1308
*/
1309
1310
/*! \fn template <typename T> void QList<T>::pop_front()
1311
1312
This function is provided for STL compatibility. It is equivalent
1313
to removeFirst().
1314
*/
1315
1316
/*! \fn template <typename T> void QList<T>::pop_back()
1317
1318
This function is provided for STL compatibility. It is equivalent
1319
to removeLast().
1320
*/
1321
1322
/*! \fn template <typename T> T& QList<T>::front()
1323
1324
This function is provided for STL compatibility. It is equivalent
1325
to first().
1326
*/
1327
1328
/*! \fn template <typename T> QList<T>::const_reference QList<T>::front() const
1329
1330
\overload
1331
*/
1332
1333
/*! \fn template <typename T> QList<T>::reference QList<T>::back()
1334
1335
This function is provided for STL compatibility. It is equivalent
1336
to last().
1337
*/
1338
1339
/*! \fn template <typename T> QList<T>::const_reference QList<T>::back() const
1340
1341
\overload
1342
*/
1343
1344
/*! \fn template <typename T> void QList<T>::shrink_to_fit()
1345
\since 5.10
1346
1347
This function is provided for STL compatibility. It is equivalent
1348
to squeeze().
1349
*/
1350
1351
/*! \fn template <typename T> bool QList<T>::empty() const
1352
1353
This function is provided for STL compatibility. It is equivalent
1354
to isEmpty(), returning \c true if the list is empty; otherwise
1355
returns \c false.
1356
*/
1357
1358
/*! \fn template <typename T> qsizetype QList<T>::max_size() const
1359
\fn template <typename T> qsizetype QList<T>::maxSize()
1360
\since 6.8
1361
1362
It returns the maximum number of elements that the list can
1363
theoretically hold. In practice, the number can be much smaller,
1364
limited by the amount of memory available to the system.
1365
*/
1366
1367
/*! \fn template <typename T> QList<T> &QList<T>::operator+=(const QList<T> &other)
1368
1369
Appends the items of the \a other list to this list and
1370
returns a reference to this list.
1371
1372
\sa operator+(), append()
1373
*/
1374
1375
/*! \fn template <typename T> QList<T> &QList<T>::operator+=(QList<T> &&other)
1376
\since 6.0
1377
1378
\overload
1379
1380
\sa operator+(), append()
1381
*/
1382
1383
/*! \fn template <typename T> void QList<T>::operator+=(parameter_type value)
1384
1385
\overload
1386
1387
Appends \a value to the list.
1388
1389
\sa append(), operator<<()
1390
*/
1391
1392
/*! \fn template <typename T> void QList<T>::operator+=(rvalue_ref value)
1393
\since 5.11
1394
1395
\overload
1396
1397
\sa append(), operator<<()
1398
*/
1399
1400
/*!
1401
\fn template <typename T> QList<T> QList<T>::operator+(const QList<T> &other) const &
1402
\fn template <typename T> QList<T> QList<T>::operator+(const QList<T> &other) &&
1403
\fn template <typename T> QList<T> QList<T>::operator+(QList<T> &&other) const &
1404
\fn template <typename T> QList<T> QList<T>::operator+(QList<T> &&other) &&
1405
1406
Returns a list that contains all the items in this list
1407
followed by all the items in the \a other list.
1408
1409
\sa operator+=()
1410
*/
1411
1412
/*! \fn template <typename T> QList<T> &QList<T>::operator<<(parameter_type value)
1413
1414
Appends \a value to the list and returns a reference to this list.
1415
1416
\sa append(), operator+=()
1417
*/
1418
1419
/*! \fn template <typename T> QList<T> &QList<T>::operator<<(rvalue_ref value)
1420
\since 5.11
1421
1422
\overload
1423
1424
\sa append(), operator+=()
1425
*/
1426
1427
1428
/*! \fn template <typename T> QList<T> &QList<T>::operator<<(const QList<T> &other)
1429
1430
Appends \a other to the list and returns a reference to the list.
1431
*/
1432
1433
/*! \fn template <typename T> QList<T> &QList<T>::operator<<(QList<T> &&other)
1434
\since 6.0
1435
1436
\overload
1437
*/
1438
1439
/*! \class QList::iterator
1440
\inmodule QtCore
1441
\brief Provides an STL-style non-const iterator for QList and QStack.
1442
1443
QList provides both \l{STL-style iterators} and \l{Java-style
1444
iterators}.
1445
1446
//! [iterator-invalidation-class-desc]
1447
\warning Iterators on implicitly shared containers do not work
1448
exactly like STL-iterators. You should avoid copying a container
1449
while iterators are active on that container. For more information,
1450
read \l{Implicit sharing iterator problem}.
1451
1452
\warning Iterators are invalidated when QList is modified. Consider that all
1453
iterators are invalidated by default. Exceptions to this rule are explicitly
1454
documented.
1455
//! [iterator-invalidation-class-desc]
1456
1457
\sa QList::begin(), QList::end(), QList::const_iterator, QMutableListIterator
1458
*/
1459
1460
/*! \class QList::const_iterator
1461
\inmodule QtCore
1462
\brief Provides an STL-style const iterator for QList and QStack.
1463
1464
QList provides both \l{STL-style iterators} and \l{Java-style
1465
iterators}.
1466
1467
\include qlist.qdoc iterator-invalidation-class-desc
1468
1469
\sa QList::constBegin(), QList::constEnd(), QList::iterator, QListIterator
1470
*/
1471
1472
/*! \typedef QList::reverse_iterator
1473
\since 5.6
1474
1475
The QList::reverse_iterator typedef provides an STL-style non-const
1476
reverse iterator for QList.
1477
1478
\include qlist.qdoc iterator-invalidation-class-desc
1479
1480
\sa QList::rbegin(), QList::rend(), QList::const_reverse_iterator, QList::iterator
1481
*/
1482
1483
/*! \typedef QList::const_reverse_iterator
1484
\since 5.6
1485
1486
The QList::const_reverse_iterator typedef provides an STL-style const
1487
reverse iterator for QList.
1488
1489
\include qlist.qdoc iterator-invalidation-class-desc
1490
1491
\sa QList::rbegin(), QList::rend(), QList::reverse_iterator, QList::const_iterator
1492
*/
1493
1494
/*! \typedef QList::Iterator
1495
1496
Qt-style synonym for QList::iterator.
1497
*/
1498
1499
/*! \typedef QList::ConstIterator
1500
1501
Qt-style synonym for QList::const_iterator.
1502
*/
1503
1504
/*! \typedef QList::const_pointer
1505
1506
Provided for STL compatibility.
1507
*/
1508
1509
/*! \typedef QList::const_reference
1510
1511
Provided for STL compatibility.
1512
*/
1513
1514
/*! \typedef QList::difference_type
1515
1516
Provided for STL compatibility.
1517
*/
1518
1519
/*! \typedef QList::pointer
1520
1521
Provided for STL compatibility.
1522
*/
1523
1524
/*! \typedef QList::reference
1525
1526
Provided for STL compatibility.
1527
*/
1528
1529
/*! \typedef QList::size_type
1530
1531
Provided for STL compatibility.
1532
*/
1533
1534
/*! \typedef QList::value_type
1535
1536
Provided for STL compatibility.
1537
*/
1538
1539
/*! \typedef QList::parameter_type
1540
1541
*/
1542
1543
/*! \typedef QList::rvalue_ref
1544
1545
*/
1546
1547
/*! \fn template <typename T> QList<T> QList<T>::toList() const
1548
\fn template <typename T> QList<T> QList<T>::toVector() const
1549
\deprecated [6.0]
1550
1551
A no-op in Qt 6. Provided for backwards compatibility with
1552
Qt 5, where QList and QVector where two different types.
1553
1554
Returns this list.
1555
*/
1556
1557
/*! \fn template <typename T> QList<T> QList<T>::fromList(const QList<T> &list)
1558
\fn template <typename T> QList<T> QList<T>::fromVector(const QList<T> &list)
1559
\deprecated [6.0]
1560
1561
A no-op in Qt 6. Provided for backwards compatibility with
1562
Qt 5, where QList and QVector were two different types.
1563
1564
Returns this list.
1565
*/
1566
1567
/*! \fn template <typename T> QDataStream &operator<<(QDataStream &out, const QList<T> &list)
1568
\relates QList
1569
1570
Writes the list \a list to stream \a out.
1571
1572
This function requires the value type to implement \c operator<<().
1573
1574
\sa{Serializing Qt Data Types}{Format of the QDataStream operators}
1575
*/
1576
1577
/*! \fn template <typename T> QDataStream &operator>>(QDataStream &in, QList<T> &list)
1578
\relates QList
1579
1580
Reads a list from stream \a in into \a list.
1581
1582
This function requires the value type to implement \c operator>>().
1583
1584
\sa{Serializing Qt Data Types}{Format of the QDataStream operators}
1585
*/
1586
1587
/*! \fn template <typename T, typename AT> qsizetype erase(QList<T> &list, const AT &t)
1588
\relates QList
1589
\since 6.1
1590
1591
Removes all elements that compare equal to \a t from the
1592
list \a list. Returns the number of elements removed, if any.
1593
1594
\note Unlike QList::removeAll, \a t is not allowed to be a
1595
reference to an element inside \a list. If you cannot be sure that
1596
this is not the case, take a copy of \a t and call this function
1597
with the copy.
1598
1599
\sa QList::removeAll(), erase_if
1600
*/
1601
1602
/*! \fn template <typename T, typename Predicate> qsizetype erase_if(QList<T> &list, Predicate pred)
1603
\relates QList
1604
\since 6.1
1605
1606
Removes all elements for which the predicate \a pred returns true
1607
from the list \a list. Returns the number of elements removed, if
1608
any.
1609
1610
\sa erase
1611
*/
1612
1613
/*! \fn template <typename T> QList<T>& QList<T>::assign(qsizetype n, parameter_type t)
1614
\since 6.6
1615
1616
Replaces the contents of this list with \a n copies of \a t.
1617
1618
The size of this list will be equal to \a n.
1619
1620
This function will only allocate memory if \a n exceeds the capacity of the
1621
list or this list is shared.
1622
*/
1623
1624
/*! \fn template <typename T> template <typename InputIterator, QList<T>::if_input_iterator<InputIterator>> QList<T>& QList<T>::assign(InputIterator first, InputIterator last)
1625
\since 6.6
1626
1627
Replaces the contents of this list with a copy of the elements in the
1628
iterator range [\a first, \a last).
1629
1630
The size of this list will be equal to the number of elements in the
1631
range [\a first, \a last).
1632
1633
This function will only allocate memory if the number of elements in the
1634
range exceeds the capacity of this list or this list is shared.
1635
1636
\note The behavior is undefined if either argument is an iterator into
1637
*this.
1638
1639
\constraints
1640
\c InputIterator meets the requirements of a
1641
\l {https://en.cppreference.com/w/cpp/named_req/InputIterator} {LegacyInputIterator}.
1642
*/
1643
1644
/*! \fn template <typename T> QList<T>& QList<T>::assign(std::initializer_list<T> l)
1645
\since 6.6
1646
1647
Replaces the contents of this list with a copy of the elements of
1648
\a l.
1649
1650
The size of this list will be equal to the number of elements in
1651
\a l.
1652
1653
This function only allocates memory if the number of elements in \a l
1654
exceeds the capacity of this list or this list is shared.
1655
*/
1656
1657
/*!
1658
\fn template <typename T> QList<T>::DataPointer &QList<T>::data_ptr() &;
1659
\fn template <typename T> const QList<T>::DataPointer &QList<T>::data_ptr() const &;
1660
\fn template <typename T> QList<T>::DataPointer QList<T>::data_ptr() &&;
1661
1662
\internal
1663
\since 6.10
1664
*/
qtbase
src
corelib
tools
qlist.qdoc
Generated on
for Qt by
1.16.1