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