Warning: That file was not part of the compilation database. It may have many parsing errors.

1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the documentation of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:FDL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Free Documentation License Usage
18** Alternatively, this file may be used under the terms of the GNU Free
19** Documentation License version 1.3 as published by the Free Software
20** Foundation and appearing in the file included in the packaging of
21** this file. Please review the following information to ensure
22** the GNU Free Documentation License version 1.3 requirements
23** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
24** $QT_END_LICENSE$
25**
26****************************************************************************/
27
28/*!
29 \class QVector
30 \inmodule QtCore
31 \brief The QVector class is a template class that provides a dynamic array.
32
33 \ingroup tools
34 \ingroup shared
35
36 \reentrant
37
38 QVector\<T\> is one of Qt's generic \l{container classes}. It
39 stores its items in adjacent memory locations and provides fast
40 index-based access.
41
42 QList\<T\>, QLinkedList\<T\>, QVector\<T\>, and QVarLengthArray\<T\>
43 provide similar APIs and functionality. They are often interchangeable,
44 but there are performance consequences. Here is an overview of use cases:
45
46 \list
47 \li QVector should be your default first choice.
48 QVector\<T\> will usually give better performance than QList\<T\>,
49 because QVector\<T\> always stores its items sequentially in memory,
50 where QList\<T\> will allocate its items on the heap unless
51 \c {sizeof(T) <= sizeof(void*)} and T has been declared to be
52 either a \c{Q_MOVABLE_TYPE} or a \c{Q_PRIMITIVE_TYPE} using
53 \l {Q_DECLARE_TYPEINFO}. See the \l {Pros and Cons of Using QList}
54 for an explanation.
55 \li However, QList is used throughout the Qt APIs for passing
56 parameters and for returning values. Use QList to interface with
57 those APIs.
58 \li If you need a real linked list, which guarantees
59 \l{Algorithmic Complexity}{constant time} insertions mid-list and
60 uses iterators to items rather than indexes, use QLinkedList.
61 \endlist
62
63 \note QVector and QVarLengthArray both guarantee C-compatible
64 array layout. QList does not. This might be important if your
65 application must interface with a C API.
66
67 \note Iterators into a QLinkedList and references into
68 heap-allocating QLists remain valid as long as the referenced items
69 remain in the container. This is not true for iterators and
70 references into a QVector and non-heap-allocating QLists.
71
72 Here's an example of a QVector that stores integers and a QVector
73 that stores QString values:
74
75 \snippet code/src_corelib_tools_qvector.cpp 0
76
77 QVector stores its items in a vector (array). Typically, vectors
78 are created with an initial size. For example, the following code
79 constructs a QVector with 200 elements:
80
81 \snippet code/src_corelib_tools_qvector.cpp 1
82
83 The elements are automatically initialized with a
84 \l{default-constructed value}. If you want to initialize the
85 vector with a different value, pass that value as the second
86 argument to the constructor:
87
88 \snippet code/src_corelib_tools_qvector.cpp 2
89
90 You can also call fill() at any time to fill the vector with a
91 value.
92
93 QVector uses 0-based indexes, just like C++ arrays. To access the
94 item at a particular index position, you can use operator[](). On
95 non-const vectors, operator[]() returns a reference to the item
96 that can be used on the left side of an assignment:
97
98 \snippet code/src_corelib_tools_qvector.cpp 3
99
100 For read-only access, an alternative syntax is to use at():
101
102 \snippet code/src_corelib_tools_qvector.cpp 4
103
104 at() can be faster than operator[](), because it never causes a
105 \l{deep copy} to occur.
106
107 Another way to access the data stored in a QVector is to call
108 data(). The function returns a pointer to the first item in the
109 vector. You can use the pointer to directly access and modify the
110 elements stored in the vector. The pointer is also useful if you
111 need to pass a QVector to a function that accepts a plain C++
112 array.
113
114 If you want to find all occurrences of a particular value in a
115 vector, use indexOf() or lastIndexOf(). The former searches
116 forward starting from a given index position, the latter searches
117 backward. Both return the index of the matching item if they found
118 one; otherwise, they return -1. For example:
119
120 \snippet code/src_corelib_tools_qvector.cpp 5
121
122 If you simply want to check whether a vector contains a
123 particular value, use contains(). If you want to find out how
124 many times a particular value occurs in the vector, use count().
125
126 QVector provides these basic functions to add, move, and remove
127 items: insert(), replace(), remove(), prepend(), append(). With
128 the exception of append() and replace(), these functions can be slow
129 (\l{linear time}) for large vectors, because they require moving many
130 items in the vector by one position in memory. If you want a container
131 class that provides fast insertion/removal in the middle, use
132 QList or QLinkedList instead.
133
134 Unlike plain C++ arrays, QVectors can be resized at any time by
135 calling resize(). If the new size is larger than the old size,
136 QVector might need to reallocate the whole vector. QVector tries
137 to reduce the number of reallocations by preallocating up to twice
138 as much memory as the actual data needs.
139
140 If you know in advance approximately how many items the QVector
141 will contain, you can call reserve(), asking QVector to
142 preallocate a certain amount of memory. You can also call
143 capacity() to find out how much memory QVector actually
144 allocated.
145
146 Note that using non-const operators and functions can cause
147 QVector to do a deep copy of the data. This is due to \l{implicit sharing}.
148
149 QVector's value type must be an \l{assignable data type}. This
150 covers most data types that are commonly used, but the compiler
151 won't let you, for example, store a QWidget as a value; instead,
152 store a QWidget *. A few functions have additional requirements;
153 for example, indexOf() and lastIndexOf() expect the value type to
154 support \c operator==(). These requirements are documented on a
155 per-function basis.
156
157 Like the other container classes, QVector provides \l{Java-style
158 iterators} (QVectorIterator and QMutableVectorIterator) and
159 \l{STL-style iterators} (QVector::const_iterator and
160 QVector::iterator). In practice, these are rarely used, because
161 you can use indexes into the QVector.
162
163 In addition to QVector, Qt also provides QVarLengthArray, a very
164 low-level class with little functionality that is optimized for
165 speed.
166
167 QVector does \e not support inserting, prepending, appending or replacing
168 with references to its own values. Doing so will cause your application to
169 abort with an error message.
170
171 \section2 More Information on Using Qt Containers
172
173 For a detailed discussion comparing Qt containers with each other and
174 with STL containers, see \l {Understand the Qt Containers}.
175
176 \section1 Maximum size and out-of-memory conditions
177
178 The current version of QVector is limited to just under 2 GB (2^31 bytes)
179 in size. The exact value is architecture-dependent, since it depends on the
180 overhead required for managing the data block, but is no more than 32
181 bytes. The number of elements that can be stored in a QVector is that size
182 divided by the size of each element.
183
184 In case memory allocation fails, QVector will use the \l Q_CHECK_PTR macro,
185 which will throw a \c std::bad_alloc exception if the application is being
186 compiled with exception support. If exceptions are disabled, then running
187 out of memory is undefined behavior.
188
189 Note that the operating system may impose further limits on applications
190 holding a lot of allocated memory, especially large, contiguous blocks.
191 Such considerations, the configuration of such behavior or any mitigation
192 are outside the scope of the Qt API.
193
194 \sa QVectorIterator, QMutableVectorIterator, QList, QLinkedList
195*/
196
197/*!
198 \fn template <typename T> QVector<T> QVector<T>::mid(int pos, int length = -1) const
199
200 Returns a sub-vector which contains elements from this vector,
201 starting at position \a pos. If \a length is -1 (the default), all
202 elements after \a pos are included; otherwise \a length elements (or
203 all remaining elements if there are less than \a length elements)
204 are included.
205*/
206
207
208/*! \fn template <typename T> QVector<T>::QVector()
209
210 Constructs an empty vector.
211
212 \sa resize()
213*/
214
215/*!
216 \fn template <typename T> QVector<T>::QVector(QVector<T> &&other)
217
218 Move-constructs a QVector instance, making it point at the same
219 object that \a other was pointing to.
220
221 \since 5.2
222*/
223
224/*! \fn template <typename T> QVector<T>::QVector(int size)
225
226 Constructs a vector with an initial size of \a size elements.
227
228 The elements are initialized with a \l{default-constructed
229 value}.
230
231 \sa resize()
232*/
233
234/*! \fn template <typename T> QVector<T>::QVector(int size, const T &value)
235
236 Constructs a vector with an initial size of \a size elements.
237 Each element is initialized with \a value.
238
239 \sa resize(), fill()
240*/
241
242/*! \fn template <typename T> QVector<T>::QVector(const QVector<T> &other)
243
244 Constructs a copy of \a other.
245
246 This operation takes \l{Algorithmic Complexity}{constant time},
247 because QVector is \l{implicitly shared}. This makes returning
248 a QVector from a function very fast. If a shared instance is
249 modified, it will be copied (copy-on-write), and that takes
250 \l{Algorithmic Complexity}{linear time}.
251
252 \sa operator=()
253*/
254
255/*! \fn template <typename T> QVector<T>::QVector(std::initializer_list<T> args)
256 \since 4.8
257
258 Constructs a vector from the std::initializer_list given by \a args.
259
260 This constructor is only enabled if the compiler supports C++11 initializer
261 lists.
262*/
263
264/*! \fn template <typename T> template<typename InputIterator> QVector<T>::QVector(InputIterator first, InputIterator last)
265 \since 5.14
266
267 Constructs a vector with the contents in the iterator range [\a first, \a last).
268
269 The value type of \c InputIterator must be convertible to \c T.
270*/
271
272/*!
273 \fn template <typename T> QVector<T>::QVector(QArrayDataPointerRef<T> ref)
274 \internal
275*/
276
277/*! \fn template <typename T> QVector<T>::~QVector()
278
279 Destroys the vector.
280*/
281
282/*! \fn template <typename T> QVector<T> &QVector<T>::operator=(const QVector<T> &other)
283
284 Assigns \a other to this vector and returns a reference to this
285 vector.
286*/
287
288/*!
289 \fn template <typename T> QVector<T> &QVector<T>::operator=(QVector<T> &&other)
290
291 Move-assigns \a other to this QVector instance.
292
293 \since 5.2
294*/
295
296/*!
297 \fn template <typename T> QVector<T> &QVector<T>::operator=(std::initializer_list<T> args)
298
299 Assigns the collection of values in \a args to this QVector instance.
300
301 This operator is only enabled if the compiler supports C++11 initializer
302 lists.
303
304 \since 5.14
305*/
306
307/*! \fn template <typename T> void QVector<T>::swap(QVector<T> &other)
308 \since 4.8
309
310 Swaps vector \a other with this vector. This operation is very fast and
311 never fails.
312*/
313
314/*! \fn template <typename T> void QVector<T>::swapItemsAt(int i, int j)
315 \since 5.14
316
317 Exchange the item at index position \a i with the item at index
318 position \a j. This function assumes that both \a i and \a j are
319 at least 0 but less than size(). To avoid failure, test that both
320 \a i and \a j are at least 0 and less than size().
321*/
322
323
324/*! \fn template <typename T> bool QVector<T>::operator==(const QVector<T> &other) const
325
326 Returns \c true if \a other is equal to this vector; otherwise
327 returns \c false.
328
329 Two vectors are considered equal if they contain the same values
330 in the same order.
331
332 This function requires the value type to have an implementation
333 of \c operator==().
334
335 \sa operator!=()
336*/
337
338/*! \fn template <typename T> bool QVector<T>::operator!=(const QVector<T> &other) const
339
340 Returns \c true if \a other is not equal to this vector; otherwise
341 returns \c false.
342
343 Two vectors are considered equal if they contain the same values
344 in the same order.
345
346 This function requires the value type to have an implementation
347 of \c operator==().
348
349 \sa operator==()
350*/
351
352/*! \fn template <typename T> bool operator<(const QVector<T> &lhs, const QVector<T> &rhs)
353 \since 5.6
354 \relates QVector
355
356 Returns \c true if vector \a lhs is
357 \l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare}
358 {lexicographically less than} \a rhs; otherwise returns \c false.
359
360 This function requires the value type to have an implementation
361 of \c operator<().
362*/
363
364/*! \fn template <typename T> bool operator<=(const QVector<T> &lhs, const QVector<T> &rhs)
365 \since 5.6
366 \relates QVector
367
368 Returns \c true if vector \a lhs is
369 \l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare}
370 {lexicographically less than or equal to} \a rhs; otherwise returns \c false.
371
372 This function requires the value type to have an implementation
373 of \c operator<().
374*/
375
376/*! \fn template <typename T> bool operator>(const QVector<T> &lhs, const QVector<T> &rhs)
377 \since 5.6
378 \relates QVector
379
380 Returns \c true if vector \a lhs is
381 \l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare}
382 {lexicographically greater than} \a rhs; otherwise returns \c false.
383
384 This function requires the value type to have an implementation
385 of \c operator<().
386*/
387
388/*! \fn template <typename T> bool operator>=(const QVector<T> &lhs, const QVector<T> &rhs)
389 \since 5.6
390 \relates QVector
391
392 Returns \c true if vector \a lhs is
393 \l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare}
394 {lexicographically greater than or equal to} \a rhs; otherwise returns \c false.
395
396 This function requires the value type to have an implementation
397 of \c operator<().
398*/
399
400/*!
401 \fn template <typename T> uint qHash(const QVector<T> &key, uint seed = 0)
402 \since 5.6
403 \relates QVector
404
405 Returns the hash value for \a key,
406 using \a seed to seed the calculation.
407
408 This function requires qHash() to be overloaded for the value type \c T.
409*/
410
411/*! \fn template <typename T> int QVector<T>::size() const
412
413 Returns the number of items in the vector.
414
415 \sa isEmpty(), resize()
416*/
417
418/*! \fn template <typename T> bool QVector<T>::isEmpty() const
419
420 Returns \c true if the vector has size 0; otherwise returns \c false.
421
422 \sa size(), resize()
423*/
424
425/*! \fn template <typename T> void QVector<T>::resize(int size)
426
427 Sets the size of the vector to \a size. If \a size is greater than the
428 current size, elements are added to the end; the new elements are
429 initialized with a \l{default-constructed value}. If \a size is less
430 than the current size, elements are removed from the end.
431
432 Since Qt 5.6, resize() doesn't shrink the capacity anymore.
433 To shed excess capacity, use squeeze().
434
435 \sa size()
436*/
437
438/*! \fn template <typename T> int QVector<T>::capacity() const
439
440 Returns the maximum number of items that can be stored in the
441 vector without forcing a reallocation.
442
443 The sole purpose of this function is to provide a means of fine
444 tuning QVector's memory usage. In general, you will rarely ever
445 need to call this function. If you want to know how many items are
446 in the vector, call size().
447
448 \sa reserve(), squeeze()
449*/
450
451/*! \fn template <typename T> void QVector<T>::reserve(int size)
452
453 Attempts to allocate memory for at least \a size elements. If you
454 know in advance how large the vector will be, you should call this
455 function to prevent reallocations and memory fragmentation.
456
457 If \a size is an underestimate, the worst that will happen is that
458 the QVector will be a bit slower. If \a size is an overestimate, you
459 may have used more memory than the normal QVector growth strategy
460 would have allocated—or you may have used less.
461
462 An alternative to reserve() is calling resize(). Whether or not that is
463 faster than reserve() depends on the element type, because resize()
464 default-constructs all elements, and requires assignment to existing
465 entries rather than calling append(), which copy- or move-constructs.
466 For simple types, like \c int or \c double, resize() is typically faster,
467 but for anything more complex, you should prefer reserve().
468
469 \warning If the size passed to resize() was underestimated, you run out
470 of allocated space and into undefined behavior. This problem does not
471 exist with reserve(), because it treats the size as just a hint.
472
473 \sa squeeze(), capacity()
474*/
475
476/*! \fn template <typename T> void QVector<T>::squeeze()
477
478 Releases any memory not required to store the items.
479
480 The sole purpose of this function is to provide a means of fine
481 tuning QVector's memory usage. In general, you will rarely ever
482 need to call this function.
483
484 \sa reserve(), capacity()
485*/
486
487/*! \fn template <typename T> void QVector<T>::detach()
488
489 \internal
490*/
491
492/*! \fn template <typename T> bool QVector<T>::isDetached() const
493
494 \internal
495*/
496
497/*! \fn template <typename T> void QVector<T>::setSharable(bool sharable)
498
499 \internal
500*/
501
502/*! \fn template <typename T> bool QVector<T>::isSharedWith(const QVector<T> &other) const
503
504 \internal
505*/
506
507/*! \fn template <typename T> T *QVector<T>::data()
508
509 Returns a pointer to the data stored in the vector. The pointer
510 can be used to access and modify the items in the vector.
511
512 Example:
513 \snippet code/src_corelib_tools_qvector.cpp 6
514
515 The pointer remains valid as long as the vector isn't
516 reallocated.
517
518 This function is mostly useful to pass a vector to a function
519 that accepts a plain C++ array.
520
521 \sa constData(), operator[]()
522*/
523
524/*! \fn template <typename T> const T *QVector<T>::data() const
525
526 \overload
527*/
528
529/*! \fn template <typename T> const T *QVector<T>::constData() const
530
531 Returns a const pointer to the data stored in the vector. The
532 pointer can be used to access the items in the vector.
533 The pointer remains valid as long as the vector isn't
534 reallocated.
535
536 This function is mostly useful to pass a vector to a function
537 that accepts a plain C++ array.
538
539 \sa data(), operator[]()
540*/
541
542/*! \fn template <typename T> void QVector<T>::clear()
543
544 Removes all the elements from the vector.
545
546 \note Until Qt 5.6, this also released the memory used by
547 the vector. From Qt 5.7, the capacity is preserved. To shed
548 all capacity, swap with a default-constructed vector:
549 \code
550 QVector<T> v ...;
551 QVector<T>().swap(v);
552 Q_ASSERT(v.capacity() == 0);
553 \endcode
554 or call squeeze().
555
556 \sa squeeze()
557*/
558
559/*! \fn template <typename T> const T &QVector<T>::at(int i) const
560
561 Returns the item at index position \a i in the vector.
562
563 \a i must be a valid index position in the vector (i.e., 0 <= \a
564 i < size()).
565
566 \sa value(), operator[]()
567*/
568
569/*! \fn template <typename T> T &QVector<T>::operator[](int i)
570
571 Returns the item at index position \a i as a modifiable reference.
572
573 \a i must be a valid index position in the vector (i.e., 0 <= \a i
574 < size()).
575
576 Note that using non-const operators can cause QVector to do a deep
577 copy.
578
579 \sa at(), value()
580*/
581
582/*! \fn template <typename T> const T &QVector<T>::operator[](int i) const
583
584 \overload
585
586 Same as at(\a i).
587*/
588
589/*!
590 \fn template <typename T> void QVector<T>::append(const T &value)
591
592 Inserts \a value at the end of the vector.
593
594 Example:
595 \snippet code/src_corelib_tools_qvector.cpp 7
596
597 This is the same as calling resize(size() + 1) and assigning \a
598 value to the new last element in the vector.
599
600 This operation is relatively fast, because QVector typically
601 allocates more memory than necessary, so it can grow without
602 reallocating the entire vector each time.
603
604 \sa operator<<(), prepend(), insert()
605*/
606
607/*!
608 \fn template <typename T> void QVector<T>::append(T &&value)
609 \since 5.6
610
611 \overload
612
613 Example:
614 \snippet code/src_corelib_tools_qvector.cpp move-append
615*/
616
617/*! \fn template <typename T> void QVector<T>::append(const QVector<T> &value)
618
619 \overload
620
621 \since 5.5
622
623 Appends the items of the \a value vector to this vector.
624
625 \sa operator<<(), operator+=()
626*/
627
628
629/*!
630 \fn template <typename T> void QVector<T>::prepend(const T &value)
631 \fn template <typename T> void QVector<T>::prepend(T &&value)
632
633 Inserts \a value at the beginning of the vector.
634
635 Example:
636 \snippet code/src_corelib_tools_qvector.cpp 8
637
638 This is the same as vector.insert(0, \a value).
639
640 For large vectors, this operation can be slow (\l{linear time}),
641 because it requires moving all the items in the vector by one
642 position further in memory. If you want a container class that
643 provides a fast prepend() function, use QList or QLinkedList
644 instead.
645
646 \sa append(), insert()
647*/
648
649/*! \fn template <typename T> void QVector<T>::insert(int i, const T &value)
650 \fn template <typename T> void QVector<T>::insert(int i, T &&value)
651
652 Inserts \a value at index position \a i in the vector. If \a i is
653 0, the value is prepended to the vector. If \a i is size(), the
654 value is appended to the vector.
655
656 Example:
657 \snippet code/src_corelib_tools_qvector.cpp 9
658
659 For large vectors, this operation can be slow (\l{linear time}),
660 because it requires moving all the items at indexes \a i and
661 above by one position further in memory. If you want a container
662 class that provides a fast insert() function, use QLinkedList
663 instead.
664
665 \sa append(), prepend(), remove()
666*/
667
668/*! \fn template <typename T> void QVector<T>::insert(int i, int count, const T &value)
669
670 \overload
671
672 Inserts \a count copies of \a value at index position \a i in the
673 vector.
674
675 Example:
676 \snippet code/src_corelib_tools_qvector.cpp 10
677*/
678
679/*!
680 \fn template <typename T> QVector<T>::iterator QVector<T>::insert(iterator before, const T &value)
681 \fn template <typename T> QVector<T>::iterator QVector<T>::insert(iterator before, T &&value)
682
683 \overload
684
685 Inserts \a value in front of the item pointed to by the iterator
686 \a before. Returns an iterator pointing at the inserted item.
687*/
688
689/*! \fn template <typename T> QVector<T>::iterator QVector<T>::insert(iterator before, int count, const T &value)
690
691 Inserts \a count copies of \a value in front of the item pointed to
692 by the iterator \a before. Returns an iterator pointing at the
693 first of the inserted items.
694*/
695
696/*! \fn template <typename T> void QVector<T>::replace(int i, const T &value)
697
698 Replaces the item at index position \a i with \a value.
699
700 \a i must be a valid index position in the vector (i.e., 0 <= \a
701 i < size()).
702
703 \sa operator[](), remove()
704*/
705
706/*! \fn template <typename T> void QVector<T>::remove(int i)
707
708 \overload
709
710 Removes the element at index position \a i.
711
712 \sa insert(), replace(), fill()
713*/
714
715/*! \fn template <typename T> void QVector<T>::remove(int i, int count)
716
717 \overload
718
719 Removes \a count elements from the middle of the vector, starting at
720 index position \a i.
721
722 \sa insert(), replace(), fill()
723*/
724
725/*! \fn template <typename T> void QVector<T>::removeAt(int i)
726 \since 5.2
727
728 Removes the element at index position \a i.
729 Equivalent to
730 \code
731 remove(i);
732 \endcode
733
734 Provided for compatibility with QList.
735
736 \sa remove(), QList::removeAt()
737*/
738
739/*! \fn template <typename T> int QVector<T>::removeAll(const T &t)
740 \since 5.4
741
742 Removes all elements that compare equal to \a t from the
743 vector. Returns the number of elements removed, if any.
744
745 Provided for compatibility with QList.
746
747 \sa removeOne(), QList::removeAll()
748*/
749
750/*! \fn template <typename T> bool QVector<T>::removeOne(const T &t)
751 \since 5.4
752
753 Removes the first element that compares equal to \a t from the
754 vector. Returns whether an element was, in fact, removed.
755
756 Provided for compatibility with QList.
757
758 \sa removeAll(), QList::removeOne()
759*/
760
761/*! \fn template <typename T> int QVector<T>::length() const
762 \since 5.2
763
764 Same as size() and count().
765
766 Provided for compatibility with QList.
767
768 \sa size(), count(), QList::length()
769*/
770
771/*! \fn template <typename T> T QVector<T>::takeAt(int i)
772 \since 5.2
773
774 Removes the element at index position \a i and returns it.
775
776 Equivalent to
777 \code
778 T t = at(i);
779 remove(i);
780 return t;
781 \endcode
782
783 Provided for compatibility with QList.
784
785 \sa takeFirst(), takeLast(), QList::takeAt()
786*/
787
788/*! \fn template <typename T> void QVector<T>::move(int from, int to)
789 \since 5.6
790
791 Moves the item at index position \a from to index position \a to.
792
793 Provided for compatibility with QList.
794
795 \sa QList::move()
796*/
797
798/*! \fn template <typename T> void QVector<T>::removeFirst()
799 \since 5.1
800 Removes the first item in the vector. Calling this function is
801 equivalent to calling remove(0). The vector must not be empty. If
802 the vector can be empty, call isEmpty() before calling this
803 function.
804
805 \sa remove(), takeFirst(), isEmpty()
806*/
807
808/*! \fn template <typename T> void QVector<T>::removeLast()
809 \since 5.1
810 Removes the last item in the vector. Calling this function is
811 equivalent to calling remove(size() - 1). The vector must not be
812 empty. If the vector can be empty, call isEmpty() before calling
813 this function.
814
815 \sa remove(), takeLast(), removeFirst(), isEmpty()
816*/
817
818/*! \fn template <typename T> T QVector<T>::takeFirst()
819 \since 5.1
820
821 Removes the first item in the vector and returns it. This function
822 assumes the vector is not empty. To avoid failure, call isEmpty()
823 before calling this function.
824
825 \sa takeLast(), removeFirst()
826*/
827
828/*! \fn template <typename T> T QVector<T>::takeLast()
829 \since 5.1
830
831 Removes the last item in the list and returns it. This function
832 assumes the vector is not empty. To avoid failure, call isEmpty()
833 before calling this function.
834
835 If you don't use the return value, removeLast() is more
836 efficient.
837
838 \sa takeFirst(), removeLast()
839*/
840
841
842/*! \fn template <typename T> QVector<T> &QVector<T>::fill(const T &value, int size = -1)
843
844 Assigns \a value to all items in the vector. If \a size is
845 different from -1 (the default), the vector is resized to size \a
846 size beforehand.
847
848 Example:
849 \snippet code/src_corelib_tools_qvector.cpp 11
850
851 \sa resize()
852*/
853
854/*! \fn template <typename T> int QVector<T>::indexOf(const T &value, int from = 0) const
855
856 Returns the index position of the first occurrence of \a value in
857 the vector, searching forward from index position \a from.
858 Returns -1 if no item matched.
859
860 Example:
861 \snippet code/src_corelib_tools_qvector.cpp 12
862
863 This function requires the value type to have an implementation of
864 \c operator==().
865
866 \sa lastIndexOf(), contains()
867*/
868
869/*! \fn template <typename T> int QVector<T>::lastIndexOf(const T &value, int from = -1) const
870
871 Returns the index position of the last occurrence of the value \a
872 value in the vector, searching backward from index position \a
873 from. If \a from is -1 (the default), the search starts at the
874 last item. Returns -1 if no item matched.
875
876 Example:
877 \snippet code/src_corelib_tools_qvector.cpp 13
878
879 This function requires the value type to have an implementation of
880 \c operator==().
881
882 \sa indexOf()
883*/
884
885/*! \fn template <typename T> bool QVector<T>::contains(const T &value) const
886
887 Returns \c true if the vector contains an occurrence of \a value;
888 otherwise returns \c false.
889
890 This function requires the value type to have an implementation of
891 \c operator==().
892
893 \sa indexOf(), count()
894*/
895
896/*! \fn template <typename T> bool QVector<T>::startsWith(const T &value) const
897 \since 4.5
898
899 Returns \c true if this vector is not empty and its first
900 item is equal to \a value; otherwise returns \c false.
901
902 \sa isEmpty(), first()
903*/
904
905/*! \fn template <typename T> bool QVector<T>::endsWith(const T &value) const
906 \since 4.5
907
908 Returns \c true if this vector is not empty and its last
909 item is equal to \a value; otherwise returns \c false.
910
911 \sa isEmpty(), last()
912*/
913
914
915/*! \fn template <typename T> int QVector<T>::count(const T &value) const
916
917 Returns the number of occurrences of \a value in the vector.
918
919 This function requires the value type to have an implementation of
920 \c operator==().
921
922 \sa contains(), indexOf()
923*/
924
925/*! \fn template <typename T> int QVector<T>::count() const
926
927 \overload
928
929 Same as size().
930*/
931
932/*! \fn template <typename T> QVector<T>::iterator QVector<T>::begin()
933
934 Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first item in
935 the vector.
936
937 \sa constBegin(), end()
938*/
939
940/*! \fn template <typename T> QVector<T>::const_iterator QVector<T>::begin() const
941
942 \overload
943*/
944
945/*! \fn template <typename T> QVector<T>::const_iterator QVector<T>::cbegin() const
946 \since 5.0
947
948 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item
949 in the vector.
950
951 \sa begin(), cend()
952*/
953
954/*! \fn template <typename T> QVector<T>::const_iterator QVector<T>::constBegin() const
955
956 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item
957 in the vector.
958
959 \sa begin(), constEnd()
960*/
961
962/*! \fn template <typename T> QVector<T>::iterator QVector<T>::end()
963
964 Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item
965 after the last item in the vector.
966
967 \sa begin(), constEnd()
968*/
969
970/*! \fn template <typename T> QVector<T>::const_iterator QVector<T>::end() const
971
972 \overload
973*/
974
975/*! \fn template <typename T> QVector<T>::const_iterator QVector<T>::cend() const
976 \since 5.0
977
978 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary
979 item after the last item in the vector.
980
981 \sa cbegin(), end()
982*/
983
984/*! \fn template <typename T> QVector<T>::const_iterator QVector<T>::constEnd() const
985
986 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary
987 item after the last item in the vector.
988
989 \sa constBegin(), end()
990*/
991
992/*! \fn template <typename T> QVector<T>::reverse_iterator QVector<T>::rbegin()
993 \since 5.6
994
995 Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to the first
996 item in the vector, in reverse order.
997
998 \sa begin(), crbegin(), rend()
999*/
1000
1001/*! \fn template <typename T> QVector<T>::const_reverse_iterator QVector<T>::rbegin() const
1002 \since 5.6
1003 \overload
1004*/
1005
1006/*! \fn template <typename T> QVector<T>::const_reverse_iterator QVector<T>::crbegin() const
1007 \since 5.6
1008
1009 Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing to the first
1010 item in the vector, in reverse order.
1011
1012 \sa begin(), rbegin(), rend()
1013*/
1014
1015/*! \fn template <typename T> QVector<T>::reverse_iterator QVector<T>::rend()
1016 \since 5.6
1017
1018 Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to one past
1019 the last item in the vector, in reverse order.
1020
1021 \sa end(), crend(), rbegin()
1022*/
1023
1024/*! \fn template <typename T> QVector<T>::const_reverse_iterator QVector<T>::rend() const
1025 \since 5.6
1026 \overload
1027*/
1028
1029/*! \fn template <typename T> QVector<T>::const_reverse_iterator QVector<T>::crend() const
1030 \since 5.6
1031
1032 Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing to one
1033 past the last item in the vector, in reverse order.
1034
1035 \sa end(), rend(), rbegin()
1036*/
1037
1038/*! \fn template <typename T> QVector<T>::iterator QVector<T>::erase(iterator pos)
1039
1040 Removes the item pointed to by the iterator \a pos from the
1041 vector, and returns an iterator to the next item in the vector
1042 (which may be end()).
1043
1044 \sa insert(), remove()
1045*/
1046
1047/*! \fn template <typename T> QVector<T>::iterator QVector<T>::erase(iterator begin, iterator end)
1048
1049 \overload
1050
1051 Removes all the items from \a begin up to (but not including) \a
1052 end. Returns an iterator to the same item that \a end referred to
1053 before the call.
1054*/
1055
1056/*! \fn template <typename T> T& QVector<T>::first()
1057
1058 Returns a reference to the first item in the vector. This
1059 function assumes that the vector isn't empty.
1060
1061 \sa last(), isEmpty(), constFirst()
1062*/
1063
1064/*! \fn template <typename T> const T& QVector<T>::first() const
1065
1066 \overload
1067*/
1068
1069/*! \fn template <typename T> const T& QVector<T>::constFirst() const
1070 \since 5.6
1071
1072 Returns a const reference to the first item in the vector. This
1073 function assumes that the vector isn't empty.
1074
1075 \sa constLast(), isEmpty(), first()
1076*/
1077
1078/*! \fn template <typename T> T& QVector<T>::last()
1079
1080 Returns a reference to the last item in the vector. This function
1081 assumes that the vector isn't empty.
1082
1083 \sa first(), isEmpty(), constLast()
1084*/
1085
1086/*! \fn template <typename T> const T& QVector<T>::last() const
1087
1088 \overload
1089*/
1090
1091/*! \fn template <typename T> const T& QVector<T>::constLast() const
1092 \since 5.6
1093
1094 Returns a const reference to the last item in the vector. This function
1095 assumes that the vector isn't empty.
1096
1097 \sa constFirst(), isEmpty(), last()
1098*/
1099
1100/*! \fn template <typename T> T QVector<T>::value(int i) const
1101
1102 Returns the value at index position \a i in the vector.
1103
1104 If the index \a i is out of bounds, the function returns
1105 a \l{default-constructed value}. If you are certain that
1106 \a i is within bounds, you can use at() instead, which is slightly
1107 faster.
1108
1109 \sa at(), operator[]()
1110*/
1111
1112/*! \fn template <typename T> T QVector<T>::value(int i, const T &defaultValue) const
1113
1114 \overload
1115
1116 If the index \a i is out of bounds, the function returns
1117 \a defaultValue.
1118*/
1119
1120/*! \fn template <typename T> void QVector<T>::push_back(const T &value)
1121
1122 This function is provided for STL compatibility. It is equivalent
1123 to append(\a value).
1124*/
1125
1126/*! \fn template <typename T> void QVector<T>::push_back(T &&value)
1127 \since 5.6
1128 \overload
1129*/
1130
1131/*!
1132 \fn template <typename T> void QVector<T>::push_front(const T &value)
1133 \fn template <typename T> void QVector<T>::push_front(T &&value)
1134
1135 This function is provided for STL compatibility. It is equivalent
1136 to prepend(\a value).
1137*/
1138
1139/*! \fn template <typename T> void QVector<T>::pop_front()
1140
1141 This function is provided for STL compatibility. It is equivalent
1142 to removeFirst().
1143*/
1144
1145/*! \fn template <typename T> void QVector<T>::pop_back()
1146
1147 This function is provided for STL compatibility. It is equivalent
1148 to removeLast().
1149*/
1150
1151/*! \fn template <typename T> T& QVector<T>::front()
1152
1153 This function is provided for STL compatibility. It is equivalent
1154 to first().
1155*/
1156
1157/*! \fn template <typename T> QVector<T>::const_reference QVector<T>::front() const
1158
1159 \overload
1160*/
1161
1162/*! \fn template <typename T> QVector<T>::reference QVector<T>::back()
1163
1164 This function is provided for STL compatibility. It is equivalent
1165 to last().
1166*/
1167
1168/*! \fn template <typename T> QVector<T>::const_reference QVector<T>::back() const
1169
1170 \overload
1171*/
1172
1173/*! \fn template <typename T> void QVector<T>::shrink_to_fit()
1174 \since 5.10
1175
1176 This function is provided for STL compatibility. It is equivalent
1177 to squeeze().
1178*/
1179
1180/*! \fn template <typename T> bool QVector<T>::empty() const
1181
1182 This function is provided for STL compatibility. It is equivalent
1183 to isEmpty(), returning \c true if the vector is empty; otherwise
1184 returns \c false.
1185*/
1186
1187/*! \fn template <typename T> QVector<T> &QVector<T>::operator+=(const QVector<T> &other)
1188
1189 Appends the items of the \a other vector to this vector and
1190 returns a reference to this vector.
1191
1192 \sa operator+(), append()
1193*/
1194
1195/*! \fn template <typename T> void QVector<T>::operator+=(const T &value)
1196
1197 \overload
1198
1199 Appends \a value to the vector.
1200
1201 \sa append(), operator<<()
1202*/
1203
1204/*! \fn template <typename T> void QVector<T>::operator+=(T &&value)
1205 \since 5.11
1206
1207 \overload
1208
1209 \sa append(), operator<<()
1210*/
1211
1212/*! \fn template <typename T> QVector<T> QVector<T>::operator+(const QVector<T> &other) const
1213
1214 Returns a vector that contains all the items in this vector
1215 followed by all the items in the \a other vector.
1216
1217 \sa operator+=()
1218*/
1219
1220/*! \fn template <typename T> QVector<T> &QVector<T>::operator<<(const T &value)
1221
1222 Appends \a value to the vector and returns a reference to this
1223 vector.
1224
1225 \sa append(), operator+=()
1226*/
1227
1228/*! \fn template <typename T> QVector<T> &QVector<T>::operator<<(T &&value)
1229 \since 5.11
1230
1231 \overload
1232
1233 \sa append(), operator+=()
1234*/
1235
1236
1237/*! \fn template <typename T> QVector<T> &QVector<T>::operator<<(const QVector<T> &other)
1238
1239 Appends \a other to the vector and returns a reference to the
1240 vector.
1241*/
1242
1243/*! \typedef QVector::iterator
1244
1245 The QVector::iterator typedef provides an STL-style non-const
1246 iterator for QVector and QStack.
1247
1248 QVector provides both \l{STL-style iterators} and \l{Java-style
1249 iterators}. The STL-style non-const iterator is simply a typedef
1250 for "T *" (pointer to T).
1251
1252 \warning Iterators on implicitly shared containers do not work
1253 exactly like STL-iterators. You should avoid copying a container
1254 while iterators are active on that container. For more information,
1255 read \l{Implicit sharing iterator problem}.
1256
1257 \sa QVector::begin(), QVector::end(), QVector::const_iterator, QMutableVectorIterator
1258*/
1259
1260/*! \typedef QVector::const_iterator
1261
1262 The QVector::const_iterator typedef provides an STL-style const
1263 iterator for QVector and QStack.
1264
1265 QVector provides both \l{STL-style iterators} and \l{Java-style
1266 iterators}. The STL-style const iterator is simply a typedef for
1267 "const T *" (pointer to const T).
1268
1269 \warning Iterators on implicitly shared containers do not work
1270 exactly like STL-iterators. You should avoid copying a container
1271 while iterators are active on that container. For more information,
1272 read \l{Implicit sharing iterator problem}.
1273
1274 \sa QVector::constBegin(), QVector::constEnd(), QVector::iterator, QVectorIterator
1275*/
1276
1277/*! \typedef QVector::reverse_iterator
1278 \since 5.6
1279
1280 The QVector::reverse_iterator typedef provides an STL-style non-const
1281 reverse iterator for QVector.
1282
1283 It is simply a typedef for \c{std::reverse_iterator<T*>}.
1284
1285 \warning Iterators on implicitly shared containers do not work
1286 exactly like STL-iterators. You should avoid copying a container
1287 while iterators are active on that container. For more information,
1288 read \l{Implicit sharing iterator problem}.
1289
1290 \sa QVector::rbegin(), QVector::rend(), QVector::const_reverse_iterator, QVector::iterator
1291*/
1292
1293/*! \typedef QVector::const_reverse_iterator
1294 \since 5.6
1295
1296 The QVector::const_reverse_iterator typedef provides an STL-style const
1297 reverse iterator for QVector.
1298
1299 It is simply a typedef for \c{std::reverse_iterator<const T*>}.
1300
1301 \warning Iterators on implicitly shared containers do not work
1302 exactly like STL-iterators. You should avoid copying a container
1303 while iterators are active on that container. For more information,
1304 read \l{Implicit sharing iterator problem}.
1305
1306 \sa QVector::rbegin(), QVector::rend(), QVector::reverse_iterator, QVector::const_iterator
1307*/
1308
1309/*! \typedef QVector::Iterator
1310
1311 Qt-style synonym for QVector::iterator.
1312*/
1313
1314/*! \typedef QVector::ConstIterator
1315
1316 Qt-style synonym for QVector::const_iterator.
1317*/
1318
1319/*! \typedef QVector::const_pointer
1320
1321 Typedef for const T *. Provided for STL compatibility.
1322*/
1323
1324/*! \typedef QVector::const_reference
1325
1326 Typedef for T &. Provided for STL compatibility.
1327*/
1328
1329/*! \typedef QVector::difference_type
1330
1331 Typedef for ptrdiff_t. Provided for STL compatibility.
1332*/
1333
1334/*! \typedef QVector::pointer
1335
1336 Typedef for T *. Provided for STL compatibility.
1337*/
1338
1339/*! \typedef QVector::reference
1340
1341 Typedef for T &. Provided for STL compatibility.
1342*/
1343
1344/*! \typedef QVector::size_type
1345
1346 Typedef for int. Provided for STL compatibility.
1347*/
1348
1349/*! \typedef QVector::value_type
1350
1351 Typedef for T. Provided for STL compatibility.
1352*/
1353
1354/*! \fn template <typename T> QList<T> QVector<T>::toList() const
1355
1356 Returns a QList object with the data contained in this QVector.
1357
1358 Example:
1359
1360 \snippet code/src_corelib_tools_qvector.cpp 14
1361
1362 \sa fromList(), QList::fromVector()
1363*/
1364
1365/*! \fn template <typename T> QVector<T> QVector<T>::fromList(const QList<T> &list)
1366
1367 Returns a QVector object with the data contained in \a list.
1368
1369 Example:
1370
1371 \snippet code/src_corelib_tools_qvector.cpp 15
1372
1373 \sa toList(), QList::toVector()
1374*/
1375
1376/*! \fn template <typename T> QVector<T> QVector<T>::fromStdVector(const std::vector<T> &vector)
1377
1378 Returns a QVector object with the data contained in \a vector. The
1379 order of the elements in the QVector is the same as in \a vector.
1380
1381 Example:
1382
1383 \snippet code/src_corelib_tools_qvector.cpp 16
1384
1385 \sa toStdVector(), QList::fromStdList()
1386*/
1387
1388/*! \fn template <typename T> std::vector<T> QVector<T>::toStdVector() const
1389
1390 Returns a std::vector object with the data contained in this QVector.
1391 Example:
1392
1393 \snippet code/src_corelib_tools_qvector.cpp 17
1394
1395 \sa fromStdVector(), QList::toStdList()
1396*/
1397
1398/*! \fn template <typename T> QDataStream &operator<<(QDataStream &out, const QVector<T> &vector)
1399 \relates QVector
1400
1401 Writes the vector \a vector to stream \a out.
1402
1403 This function requires the value type to implement \c operator<<().
1404
1405 \sa{Serializing Qt Data Types}{Format of the QDataStream operators}
1406*/
1407
1408/*! \fn template <typename T> QDataStream &operator>>(QDataStream &in, QVector<T> &vector)
1409 \relates QVector
1410
1411 Reads a vector from stream \a in into \a vector.
1412
1413 This function requires the value type to implement \c operator>>().
1414
1415 \sa{Serializing Qt Data Types}{Format of the QDataStream operators}
1416*/
1417

Warning: That file was not part of the compilation database. It may have many parsing errors.