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.h
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// Copyright (C) 2019 Intel Corporation
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#ifndef QLIST_H
6#define QLIST_H
7
8#include <QtCore/qarraydatapointer.h>
9#include <QtCore/qcompare.h>
10#include <QtCore/qnamespace.h>
11#include <QtCore/qhashfunctions.h>
12#include <QtCore/qiterator.h>
13#include <QtCore/qcontainertools_impl.h>
14#include <QtCore/qnamespace.h>
15#include <QtCore/qttypetraits.h>
16
17#include <functional>
18#include <limits>
19#include <initializer_list>
20#include <type_traits>
21
22class tst_QList;
23
24QT_BEGIN_NAMESPACE
25
26namespace QtPrivate {
27 template <typename V, typename U> qsizetype indexOf(const QList<V> &list, const U &u, qsizetype from) noexcept;
28 template <typename V, typename U> qsizetype lastIndexOf(const QList<V> &list, const U &u, qsizetype from) noexcept;
29}
30
31template <typename T> struct QListSpecialMethodsBase
32{
33protected:
36
37 using Self = QList<T>;
38 Self *self() { return static_cast<Self *>(this); }
39 const Self *self() const { return static_cast<const Self *>(this); }
40
41public:
42 template <typename AT = T>
43 qsizetype indexOf(const AT &t, qsizetype from = 0) const noexcept;
44 template <typename AT = T>
45 qsizetype lastIndexOf(const AT &t, qsizetype from = -1) const noexcept;
46
47 template <typename AT = T>
48 bool contains(const AT &t) const noexcept
49 {
50 return self()->indexOf(t) != -1;
51 }
52};
53template <typename T> struct QListSpecialMethods : QListSpecialMethodsBase<T>
54{
55protected:
58
59public:
61 using QListSpecialMethodsBase<T>::lastIndexOf;
62 using QListSpecialMethodsBase<T>::contains;
63};
64template <> struct QListSpecialMethods<QByteArray>;
65template <> struct QListSpecialMethods<QString>;
66
67#if !defined(QT_STRICT_QLIST_ITERATORS) && (QT_VERSION >= QT_VERSION_CHECK(6, 6, 0)) && !defined(Q_OS_WIN)
68#define QT_STRICT_QLIST_ITERATORS
69#endif
70
71#ifdef Q_QDOC // define QVector for QDoc
72template<typename T> class QVector : public QList<T> {};
73#endif
74
75template <typename T>
76class QList
77#ifndef Q_QDOC
78 : public QListSpecialMethods<T>
79#endif
80{
81 using Data = QTypedArrayData<T>;
82 using DataOps = QArrayDataOps<T>;
84 class DisableRValueRefs {};
85
86 friend class ::tst_QList;
87
88 DataPointer d;
89
90 template <typename V, typename U> friend qsizetype QtPrivate::indexOf(const QList<V> &list, const U &u, qsizetype from) noexcept;
91 template <typename V, typename U> friend qsizetype QtPrivate::lastIndexOf(const QList<V> &list, const U &u, qsizetype from) noexcept;
92 // This alias prevents the QtPrivate namespace from being exposed into the docs.
93 template <typename InputIterator>
95
96public:
97 using Type = T;
98 using value_type = T;
99 using pointer = T *;
100 using const_pointer = const T *;
101 using reference = T &;
102 using const_reference = const T &;
105#ifndef Q_QDOC
108#else // simplified aliases for QDoc
109 using parameter_type = const T &;
110 using rvalue_ref = T &&;
111#endif
112
113 DataPointer &data_ptr() & { return d; }
114 const DataPointer &data_ptr() const & { return d; }
115 DataPointer &&data_ptr() && { return std::move(d); }
116 // No current use-case for a `const &&` overload
117
118 class const_iterator;
119 class iterator {
120 friend class QList<T>;
121 friend class const_iterator;
122 T *i = nullptr;
123#ifdef QT_STRICT_QLIST_ITERATORS
124 inline constexpr explicit iterator(T *n) : i(n) {}
125#endif
126
127 public:
129 using value_type = T;
130#ifdef QT_COMPILER_HAS_LWG3346
132#endif
133 using element_type = value_type;
134 using iterator_category = std::random_access_iterator_tag;
135 using pointer = T *;
136 using reference = T &;
137
138 inline constexpr iterator() = default;
139#ifndef QT_STRICT_QLIST_ITERATORS
140 inline constexpr explicit iterator(T *n) : i(n) {}
141#endif
142 inline T &operator*() const { return *i; }
143 inline T *operator->() const { return i; }
144 inline T &operator[](qsizetype j) const { return *(i + j); }
145 inline constexpr bool operator==(iterator o) const { return i == o.i; }
146 inline constexpr bool operator!=(iterator o) const { return i != o.i; }
147 inline constexpr bool operator<(iterator other) const { return i < other.i; }
148 inline constexpr bool operator<=(iterator other) const { return i <= other.i; }
149 inline constexpr bool operator>(iterator other) const { return i > other.i; }
150 inline constexpr bool operator>=(iterator other) const { return i >= other.i; }
151 inline constexpr bool operator==(const_iterator o) const { return i == o.i; }
152 inline constexpr bool operator!=(const_iterator o) const { return i != o.i; }
153 inline constexpr bool operator<(const_iterator other) const { return i < other.i; }
154 inline constexpr bool operator<=(const_iterator other) const { return i <= other.i; }
155 inline constexpr bool operator>(const_iterator other) const { return i > other.i; }
156 inline constexpr bool operator>=(const_iterator other) const { return i >= other.i; }
157 inline constexpr bool operator==(pointer p) const { return i == p; }
158 inline constexpr bool operator!=(pointer p) const { return i != p; }
159 inline iterator &operator++() { ++i; return *this; }
160 inline iterator operator++(int) { auto copy = *this; ++*this; return copy; }
161 inline iterator &operator--() { --i; return *this; }
162 inline iterator operator--(int) { auto copy = *this; --*this; return copy; }
163 inline qsizetype operator-(iterator j) const { return i - j.i; }
164#if QT_DEPRECATED_SINCE(6, 3) && !defined(QT_STRICT_QLIST_ITERATORS)
165 QT_DEPRECATED_VERSION_X_6_3("Use operator* or operator-> rather than relying on "
166 "the implicit conversion between a QList/QVector::iterator "
167 "and a raw pointer")
168 inline operator T*() const { return i; }
169
170 template <typename Int> std::enable_if_t<std::is_integral_v<Int>, iterator>
171 &operator+=(Int j) { i+=j; return *this; }
172 template <typename Int> std::enable_if_t<std::is_integral_v<Int>, iterator>
173 &operator-=(Int j) { i-=j; return *this; }
174 template <typename Int> std::enable_if_t<std::is_integral_v<Int>, iterator>
175 operator+(Int j) const { return iterator(i+j); }
176 template <typename Int> std::enable_if_t<std::is_integral_v<Int>, iterator>
177 operator-(Int j) const { return iterator(i-j); }
178 template <typename Int> friend std::enable_if_t<std::is_integral_v<Int>, iterator>
179 operator+(Int j, iterator k) { return k + j; }
180#else
181 inline iterator &operator+=(qsizetype j) { i += j; return *this; }
182 inline iterator &operator-=(qsizetype j) { i -= j; return *this; }
183 inline iterator operator+(qsizetype j) const { return iterator(i + j); }
184 inline iterator operator-(qsizetype j) const { return iterator(i - j); }
185 friend inline iterator operator+(qsizetype j, iterator k) { return k + j; }
186#endif
187 };
188
190 friend class QList<T>;
191 friend class iterator;
192 const T *i = nullptr;
193#ifdef QT_STRICT_QLIST_ITERATORS
194 inline constexpr explicit const_iterator(const T *n) : i(n) {}
195#endif
196
197 public:
199 using value_type = T;
200#ifdef QT_COMPILER_HAS_LWG3346
202#endif
203 using element_type = const value_type;
204 using iterator_category = std::random_access_iterator_tag;
205 using pointer = const T *;
206 using reference = const T &;
207
208 inline constexpr const_iterator() = default;
209#ifndef QT_STRICT_QLIST_ITERATORS
210 inline constexpr explicit const_iterator(const T *n) : i(n) {}
211#endif
212 inline constexpr const_iterator(iterator o): i(o.i) {}
213 inline const T &operator*() const { return *i; }
214 inline const T *operator->() const { return i; }
215 inline const T &operator[](qsizetype j) const { return *(i + j); }
216 inline constexpr bool operator==(const_iterator o) const { return i == o.i; }
217 inline constexpr bool operator!=(const_iterator o) const { return i != o.i; }
218 inline constexpr bool operator<(const_iterator other) const { return i < other.i; }
219 inline constexpr bool operator<=(const_iterator other) const { return i <= other.i; }
220 inline constexpr bool operator>(const_iterator other) const { return i > other.i; }
221 inline constexpr bool operator>=(const_iterator other) const { return i >= other.i; }
222 inline constexpr bool operator==(iterator o) const { return i == o.i; }
223 inline constexpr bool operator!=(iterator o) const { return i != o.i; }
224 inline constexpr bool operator<(iterator other) const { return i < other.i; }
225 inline constexpr bool operator<=(iterator other) const { return i <= other.i; }
226 inline constexpr bool operator>(iterator other) const { return i > other.i; }
227 inline constexpr bool operator>=(iterator other) const { return i >= other.i; }
228 inline constexpr bool operator==(pointer p) const { return i == p; }
229 inline constexpr bool operator!=(pointer p) const { return i != p; }
230 inline const_iterator &operator++() { ++i; return *this; }
231 inline const_iterator operator++(int) { auto copy = *this; ++*this; return copy; }
232 inline const_iterator &operator--() { --i; return *this; }
233 inline const_iterator operator--(int) { auto copy = *this; --*this; return copy; }
234 inline qsizetype operator-(const_iterator j) const { return i - j.i; }
235#if QT_DEPRECATED_SINCE(6, 3) && !defined(QT_STRICT_QLIST_ITERATORS)
236 QT_DEPRECATED_VERSION_X_6_3("Use operator* or operator-> rather than relying on "
237 "the implicit conversion between a QList/QVector::const_iterator "
238 "and a raw pointer")
239 inline operator const T*() const { return i; }
240
241 template <typename Int> std::enable_if_t<std::is_integral_v<Int>, const_iterator>
242 &operator+=(Int j) { i+=j; return *this; }
243 template <typename Int> std::enable_if_t<std::is_integral_v<Int>, const_iterator>
244 &operator-=(Int j) { i-=j; return *this; }
245 template <typename Int> std::enable_if_t<std::is_integral_v<Int>, const_iterator>
246 operator+(Int j) const { return const_iterator(i+j); }
247 template <typename Int> std::enable_if_t<std::is_integral_v<Int>, const_iterator>
248 operator-(Int j) const { return const_iterator(i-j); }
249 template <typename Int> friend std::enable_if_t<std::is_integral_v<Int>, const_iterator>
250 operator+(Int j, const_iterator k) { return k + j; }
251#else
252 inline const_iterator &operator+=(qsizetype j) { i += j; return *this; }
253 inline const_iterator &operator-=(qsizetype j) { i -= j; return *this; }
254 inline const_iterator operator+(qsizetype j) const { return const_iterator(i + j); }
255 inline const_iterator operator-(qsizetype j) const { return const_iterator(i - j); }
256 friend inline const_iterator operator+(qsizetype j, const_iterator k) { return k + j; }
257#endif
258 };
259 using Iterator = iterator;
260 using ConstIterator = const_iterator;
261 using reverse_iterator = std::reverse_iterator<iterator>;
262 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
263
264private:
265 void resize_internal(qsizetype i);
266 bool isValidIterator(const_iterator i) const
267 {
268 const std::less<const T*> less = {};
269 return !less(d->end(), i.i) && !less(i.i, d->begin());
270 }
271
272 void verify([[maybe_unused]] qsizetype pos = 0, [[maybe_unused]] qsizetype n = 1) const
273 {
274 Q_ASSERT(pos >= 0);
275 Q_ASSERT(pos <= size());
276 Q_ASSERT(n >= 0);
277 Q_ASSERT(n <= size() - pos);
278 }
279public:
280 QList(DataPointer dd) noexcept
281 : d(dd)
282 {
283 }
284
285public:
286 constexpr QList() noexcept = default;
287 explicit QList(qsizetype size)
288 : d(size)
289 {
290 if (size)
291 d->appendInitialize(size);
292 }
293 QList(qsizetype size, parameter_type t)
294 : d(size)
295 {
296 if (size)
297 d->copyAppend(size, t);
298 }
299
300 inline QList(std::initializer_list<T> args)
301 : d(qsizetype(args.size()))
302 {
303 if (args.size())
304 d->copyAppend(args.begin(), args.end());
305 }
306
307 QList<T> &operator=(std::initializer_list<T> args)
308 {
309 return assign(args);
310 }
311
312 template <typename InputIterator, if_input_iterator<InputIterator> = true>
313 QList(InputIterator i1, InputIterator i2)
314 {
315 if constexpr (!std::is_convertible_v<typename std::iterator_traits<InputIterator>::iterator_category, std::forward_iterator_tag>) {
316 std::copy(i1, i2, std::back_inserter(*this));
317 } else {
318 const auto distance = std::distance(i1, i2);
319 if (distance) {
320 d = DataPointer(qsizetype(distance));
321 // appendIteratorRange can deal with contiguous iterators on its own,
322 // this is an optimization for C++17 code.
323 if constexpr (std::is_same_v<std::decay_t<InputIterator>, iterator> ||
324 std::is_same_v<std::decay_t<InputIterator>, const_iterator>) {
325 d->copyAppend(i1.i, i2.i);
326 } else {
327 d->appendIteratorRange(i1, i2);
328 }
329 }
330 }
331 }
332
333 // This constructor is here for compatibility with QStringList in Qt 5, that has a QStringList(const QString &) constructor
334 template<typename String, typename = std::enable_if_t<std::is_same_v<T, QString> && std::is_convertible_v<String, QString>>>
335 inline explicit QList(const String &str)
336 { append(str); }
337
338 QList(qsizetype size, Qt::Initialization)
339 : d(size)
340 {
341 if (size)
342 d->appendUninitialized(size);
343 }
344
345 // compiler-generated special member functions are fine!
346
347 void swap(QList &other) noexcept { d.swap(other.d); }
348
349#ifndef Q_QDOC
350private:
351 template <typename U = T,
352 Qt::if_has_qt_compare_three_way<U, U> = true>
353 friend auto compareThreeWay(const QList &lhs, const QList &rhs)
354 {
355 return QtOrderingPrivate::lexicographicalCompareThreeWay(lhs.begin(), lhs.end(),
356 rhs.begin(), rhs.end());
357 }
358
359#if defined(__cpp_lib_three_way_comparison) && defined(__cpp_lib_concepts)
360 template <typename U = T,
362 friend auto operator<=>(const QList &lhs, const QList &rhs)
363 {
365 rhs.begin(), rhs.end(),
367 }
368#endif // __cpp_lib_three_way_comparison && __cpp_lib_concepts
369
370public:
371 template <typename U = T>
373 {
374 if (size() != other.size())
375 return false;
376 if (begin() == other.begin())
377 return true;
378
379 // do element-by-element comparison
380 return std::equal(begin(), end(), other.begin(), other.end());
381 }
382
383 template <typename U = T>
385 {
386 return !(*this == other);
387 }
388
389#ifndef __cpp_lib_three_way_comparison
390 template <typename U = T>
391 QTypeTraits::compare_lt_result_container<QList, U> operator<(const QList &other) const
392 noexcept(noexcept(std::lexicographical_compare<typename QList<U>::const_iterator,
393 typename QList::const_iterator>(
394 std::declval<QList<U>>().begin(), std::declval<QList<U>>().end(),
395 other.begin(), other.end())))
396 {
397 return std::lexicographical_compare(begin(), end(),
398 other.begin(), other.end());
399 }
400
401 template <typename U = T>
403 noexcept(noexcept(other < std::declval<QList<U>>()))
404 {
405 return other < *this;
406 }
407
408 template <typename U = T>
409 QTypeTraits::compare_lt_result_container<QList, U> operator<=(const QList &other) const
410 noexcept(noexcept(other < std::declval<QList<U>>()))
411 {
412 return !(other < *this);
413 }
414
415 template <typename U = T>
417 noexcept(noexcept(std::declval<QList<U>>() < other))
418 {
419 return !(*this < other);
420 }
421#endif // __cpp_lib_three_way_comparison
422#else
423 bool operator==(const QList &other) const;
424 bool operator!=(const QList &other) const;
425 bool operator<(const QList &other) const;
426 bool operator>(const QList &other) const;
427 bool operator<=(const QList &other) const;
428 bool operator>=(const QList &other) const;
429 friend auto operator<=>(const QList &lhs, const QList &rhs);
430#endif // Q_QDOC
431
432 static constexpr qsizetype maxSize() { return Data::maxSize(); }
433 constexpr qsizetype size() const noexcept
434 {
435#if __has_cpp_attribute(assume)
436 constexpr size_t MaxSize = maxSize();
437 [[assume(size_t(d.size) <= MaxSize)]];
438#endif
439 return d.size;
440 }
441 constexpr qsizetype count() const noexcept { return size(); }
442 constexpr qsizetype length() const noexcept { return size(); }
443
444 constexpr bool isEmpty() const noexcept { return size() == 0; }
445
446 void resize(qsizetype size)
447 {
448 resize_internal(size);
449 if (size > this->size())
450 d->appendInitialize(size);
451 }
452 void resize(qsizetype size, parameter_type c)
453 {
454 resize_internal(size);
455 if (size > this->size())
456 d->copyAppend(size - this->size(), c);
457 }
458 void resizeForOverwrite(qsizetype size)
459 {
460 resize_internal(size);
461 if (size > this->size())
462 d->appendUninitialized(size);
463 }
464
465 inline qsizetype capacity() const { return qsizetype(d->constAllocatedCapacity()); }
466 void reserve(qsizetype size);
467 inline void squeeze();
468
469 void detach() { d.detach(); }
470 bool isDetached() const noexcept { return !d->isShared(); }
471
472 inline bool isSharedWith(const QList<T> &other) const { return d == other.d; }
473
474 pointer data() { detach(); return d->data(); }
475 const_pointer data() const noexcept { return d->data(); }
476 const_pointer constData() const noexcept { return d->data(); }
477 void clear() {
478 if (!size())
479 return;
480 if (d->needsDetach()) {
481 // must allocate memory
482 DataPointer detached(d.allocatedCapacity());
483 d.swap(detached);
484 } else {
485 d->truncate(0);
486 }
487 }
488
489 const_reference at(qsizetype i) const noexcept
490 {
491 Q_ASSERT_X(size_t(i) < size_t(d->size), "QList::at", "index out of range");
492 return data()[i];
493 }
494 reference operator[](qsizetype i)
495 {
496 Q_ASSERT_X(size_t(i) < size_t(d->size), "QList::operator[]", "index out of range");
497 // don't detach() here, we detach in data below:
498 return data()[i];
499 }
500 const_reference operator[](qsizetype i) const noexcept { return at(i); }
501 void append(parameter_type t) { emplaceBack(t); }
503 void append(rvalue_ref t)
504 {
505 if constexpr (DataPointer::pass_parameter_by_value) {
506 Q_UNUSED(t);
507 } else {
508 emplaceBack(std::move(t));
509 }
510 }
511 void append(const QList<T> &l)
512 {
513 append(l.constBegin(), l.constEnd());
514 }
515 void append(QList<T> &&l);
516 void prepend(rvalue_ref t) {
517 if constexpr (DataPointer::pass_parameter_by_value) {
518 Q_UNUSED(t);
519 } else {
520 emplaceFront(std::move(t));
521 }
522 }
523 void prepend(parameter_type t) { emplaceFront(t); }
524
525 template<typename... Args>
526 inline reference emplaceBack(Args &&... args);
527
528 template <typename ...Args>
529 inline reference emplaceFront(Args&&... args);
530
531 iterator insert(qsizetype i, parameter_type t)
532 { return emplace(i, t); }
533 iterator insert(qsizetype i, qsizetype n, parameter_type t);
534 iterator insert(const_iterator before, parameter_type t)
535 {
536 Q_ASSERT_X(isValidIterator(before), "QList::insert", "The specified iterator argument 'before' is invalid");
537 return insert(before, 1, t);
538 }
539 iterator insert(const_iterator before, qsizetype n, parameter_type t)
540 {
541 Q_ASSERT_X(isValidIterator(before), "QList::insert", "The specified iterator argument 'before' is invalid");
542 return insert(std::distance(constBegin(), before), n, t);
543 }
544 iterator insert(const_iterator before, rvalue_ref t)
545 {
546 Q_ASSERT_X(isValidIterator(before), "QList::insert", "The specified iterator argument 'before' is invalid");
547 return insert(std::distance(constBegin(), before), std::move(t));
548 }
549 iterator insert(qsizetype i, rvalue_ref t) {
550 if constexpr (DataPointer::pass_parameter_by_value) {
551 Q_UNUSED(i);
552 Q_UNUSED(t);
553 return end();
554 } else {
555 return emplace(i, std::move(t));
556 }
557 }
558
559 QList &assign(qsizetype n, parameter_type t)
560 {
561 Q_ASSERT(n >= 0);
562 return fill(t, n);
563 }
564
565 template <typename InputIterator, if_input_iterator<InputIterator> = true>
566 QList &assign(InputIterator first, InputIterator last)
567 { d.assign(first, last); return *this; }
568
569 QList &assign(std::initializer_list<T> l)
570 { return assign(l.begin(), l.end()); }
571
572 template <typename ...Args>
573 iterator emplace(const_iterator before, Args&&... args)
574 {
575 Q_ASSERT_X(isValidIterator(before), "QList::emplace", "The specified iterator argument 'before' is invalid");
576 return emplace(std::distance(constBegin(), before), std::forward<Args>(args)...);
577 }
578
579 template <typename ...Args>
580 iterator emplace(qsizetype i, Args&&... args);
581#if 0
582 template< class InputIt >
585#endif
586 void replace(qsizetype i, parameter_type t)
587 {
588 Q_ASSERT_X(i >= 0 && i < d->size, "QList<T>::replace", "index out of range");
589 DataPointer oldData;
590 d.detach(&oldData);
591 d.data()[i] = t;
592 }
593 void replace(qsizetype i, rvalue_ref t)
594 {
595 if constexpr (DataPointer::pass_parameter_by_value) {
596 Q_UNUSED(i);
597 Q_UNUSED(t);
598 } else {
599 Q_ASSERT_X(i >= 0 && i < d->size, "QList<T>::replace", "index out of range");
600 DataPointer oldData;
601 d.detach(&oldData);
602 d.data()[i] = std::move(t);
603 }
604 }
605
606 void remove(qsizetype i, qsizetype n = 1);
607 void removeFirst() noexcept;
608 void removeLast() noexcept;
609 value_type takeFirst() { Q_ASSERT(!isEmpty()); value_type v = std::move(first()); d->eraseFirst(); return v; }
610 value_type takeLast() { Q_ASSERT(!isEmpty()); value_type v = std::move(last()); d->eraseLast(); return v; }
611
612 QList<T> &fill(parameter_type t, qsizetype size = -1);
613
614#ifndef Q_QDOC
615 using QListSpecialMethods<T>::contains;
616 using QListSpecialMethods<T>::indexOf;
617 using QListSpecialMethods<T>::lastIndexOf;
618#else
619 template <typename AT>
620 qsizetype indexOf(const AT &t, qsizetype from = 0) const noexcept;
621 template <typename AT>
622 qsizetype lastIndexOf(const AT &t, qsizetype from = -1) const noexcept;
623 template <typename AT>
624 bool contains(const AT &t) const noexcept;
625#endif
626
627 template <typename AT = T>
628 qsizetype count(const AT &t) const noexcept
629 {
630 return qsizetype(std::count(data(), data() + size(), t));
631 }
632
633 void removeAt(qsizetype i) { remove(i); }
634 template <typename AT = T>
635 qsizetype removeAll(const AT &t)
636 {
637 return QtPrivate::sequential_erase_with_copy(*this, t);
638 }
639
640 template <typename AT = T>
641 bool removeOne(const AT &t)
642 {
643 return QtPrivate::sequential_erase_one(*this, t);
644 }
645
646 template <typename Predicate>
647 qsizetype removeIf(Predicate pred)
648 {
649 return QtPrivate::sequential_erase_if(*this, pred);
650 }
651
652 T takeAt(qsizetype i) { T t = std::move((*this)[i]); remove(i); return t; }
653 void move(qsizetype from, qsizetype to)
654 {
655 Q_ASSERT_X(from >= 0 && from < size(), "QList::move(qsizetype, qsizetype)", "'from' is out-of-range");
656 Q_ASSERT_X(to >= 0 && to < size(), "QList::move(qsizetype, qsizetype)", "'to' is out-of-range");
657 if (from == to) // don't detach when no-op
658 return;
659 detach();
660 T * const b = d->begin();
661 if (from < to)
662 std::rotate(b + from, b + from + 1, b + to + 1);
663 else
664 std::rotate(b + to, b + from, b + from + 1);
665 }
666
667 // STL-style
668 iterator begin() { detach(); return iterator(d->begin()); }
669 iterator end() { detach(); return iterator(d->end()); }
670
671 const_iterator begin() const noexcept { return const_iterator(d->constBegin()); }
672 const_iterator end() const noexcept { return const_iterator(d->constEnd()); }
673 const_iterator cbegin() const noexcept { return const_iterator(d->constBegin()); }
674 const_iterator cend() const noexcept { return const_iterator(d->constEnd()); }
675 const_iterator constBegin() const noexcept { return const_iterator(d->constBegin()); }
676 const_iterator constEnd() const noexcept { return const_iterator(d->constEnd()); }
677 reverse_iterator rbegin() { return reverse_iterator(end()); }
678 reverse_iterator rend() { return reverse_iterator(begin()); }
679 const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(end()); }
680 const_reverse_iterator rend() const noexcept { return const_reverse_iterator(begin()); }
681 const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(end()); }
682 const_reverse_iterator crend() const noexcept { return const_reverse_iterator(begin()); }
683
685 inline iterator erase(const_iterator pos) { return erase(pos, pos+1); }
686
687 // more Qt
688 inline T& first() { Q_ASSERT(!isEmpty()); return *begin(); }
689 inline const T &first() const noexcept { Q_ASSERT(!isEmpty()); return *begin(); }
690 inline const T &constFirst() const noexcept { Q_ASSERT(!isEmpty()); return *begin(); }
691 inline T& last() { Q_ASSERT(!isEmpty()); return *(end()-1); }
692 inline const T &last() const noexcept { Q_ASSERT(!isEmpty()); return *(end()-1); }
693 inline const T &constLast() const noexcept { Q_ASSERT(!isEmpty()); return *(end()-1); }
694 inline bool startsWith(parameter_type t) const { return !isEmpty() && first() == t; }
695 inline bool endsWith(parameter_type t) const { return !isEmpty() && last() == t; }
696 QList<T> mid(qsizetype pos, qsizetype len = -1) const;
697
698 QList<T> first(qsizetype n) const
699 { verify(0, n); return QList<T>(begin(), begin() + n); }
700 QList<T> last(qsizetype n) const
701 { verify(0, n); return QList<T>(end() - n, end()); }
702 QList<T> sliced(qsizetype pos) const
703 { verify(pos, 0); return QList<T>(begin() + pos, end()); }
704 QList<T> sliced(qsizetype pos, qsizetype n) const
705 { verify(pos, n); return QList<T>(begin() + pos, begin() + pos + n); }
706
707 T value(qsizetype i) const { return value(i, T()); }
708 T value(qsizetype i, parameter_type defaultValue) const;
709
710 void swapItemsAt(qsizetype i, qsizetype j) {
711 Q_ASSERT_X(i >= 0 && i < size() && j >= 0 && j < size(),
712 "QList<T>::swap", "index out of range");
713 detach();
714 qSwap(d->begin()[i], d->begin()[j]);
715 }
716
717 // STL compatibility
718 inline void push_back(parameter_type t) { append(t); }
719 void push_back(rvalue_ref t) { append(std::move(t)); }
720 void push_front(rvalue_ref t) { prepend(std::move(t)); }
721 inline void push_front(parameter_type t) { prepend(t); }
722 void pop_back() noexcept { removeLast(); }
723 void pop_front() noexcept { removeFirst(); }
724
725 template <typename ...Args>
726 reference emplace_back(Args&&... args) { return emplaceBack(std::forward<Args>(args)...); }
727
728 inline bool empty() const noexcept
729 { return d->size == 0; }
730 inline reference front() { return first(); }
731 inline const_reference front() const noexcept { return first(); }
732 inline reference back() { return last(); }
733 inline const_reference back() const noexcept { return last(); }
735 constexpr qsizetype max_size() const noexcept
736 {
737 return maxSize();
738 }
739
740 // comfort
741 QList<T> &operator+=(const QList<T> &l) { append(l); return *this; }
742 QList<T> &operator+=(QList<T> &&l) { append(std::move(l)); return *this; }
743 inline QList<T> operator+(const QList<T> &l) const &
744 { QList n = *this; n += l; return n; }
745 QList<T> operator+(const QList<T> &l) &&
746 { return std::move(*this += l); }
747 inline QList<T> operator+(QList<T> &&l) const &
748 { QList n = *this; n += std::move(l); return n; }
749 QList<T> operator+(QList<T> &&l) &&
750 { return std::move(*this += std::move(l)); }
751 inline QList<T> &operator+=(parameter_type t)
752 { append(t); return *this; }
753 inline QList<T> &operator<< (parameter_type t)
754 { append(t); return *this; }
755 inline QList<T> &operator<<(const QList<T> &l)
756 { *this += l; return *this; }
757 inline QList<T> &operator<<(QList<T> &&l)
758 { *this += std::move(l); return *this; }
759 inline QList<T> &operator+=(rvalue_ref t)
760 { append(std::move(t)); return *this; }
761 inline QList<T> &operator<<(rvalue_ref t)
762 { append(std::move(t)); return *this; }
763
764 // Consider deprecating in 6.4 or later
765 static QList<T> fromList(const QList<T> &list) noexcept { return list; }
766 QList<T> toList() const noexcept { return *this; }
767
768 static inline QList<T> fromVector(const QList<T> &vector) noexcept { return vector; }
769 inline QList<T> toVector() const noexcept { return *this; }
770
771 template<qsizetype N>
772 static QList<T> fromReadOnlyData(const T (&t)[N]) noexcept
773 {
774 return QList<T>({ nullptr, const_cast<T *>(t), N });
775 }
776};
777
778template <typename InputIterator,
779 typename ValueType = typename std::iterator_traits<InputIterator>::value_type,
780 QtPrivate::IfIsInputIterator<InputIterator> = true>
781QList(InputIterator, InputIterator) -> QList<ValueType>;
782
783template <typename T>
784inline void QList<T>::resize_internal(qsizetype newSize)
785{
786 Q_ASSERT(newSize >= 0);
787
788 if (d->needsDetach() || newSize > capacity() - d.freeSpaceAtBegin()) {
789 d.detachAndGrow(QArrayData::GrowsAtEnd, newSize - d.size, nullptr, nullptr);
790 } else if (newSize < size()) {
791 d->truncate(newSize);
792 }
793}
794
795template <typename T>
796void QList<T>::reserve(qsizetype asize)
797{
798 // capacity() == 0 for immutable data, so this will force a detaching below
799 if (asize <= capacity() - d.freeSpaceAtBegin()) {
800 if (d->flags() & Data::CapacityReserved)
801 return; // already reserved, don't shrink
802 if (!d->isShared()) {
803 // accept current allocation, don't shrink
804 d->setFlag(Data::CapacityReserved);
805 return;
806 }
807 }
808
809 DataPointer detached(qMax(asize, size()));
810 detached->copyAppend(d->begin(), d->end());
811 if (detached.d_ptr())
812 detached->setFlag(Data::CapacityReserved);
813 d.swap(detached);
814}
815
816template <typename T>
817inline void QList<T>::squeeze()
818{
819 if (!d.isMutable())
820 return;
821 if (d->needsDetach() || size() < capacity()) {
822 // must allocate memory
823 DataPointer detached(size());
824 if (size()) {
825 if (d.needsDetach())
826 detached->copyAppend(d.data(), d.data() + d.size);
827 else
828 detached->moveAppend(d.data(), d.data() + d.size);
829 }
830 d.swap(detached);
831 }
832 // We're detached so this is fine
833 d->clearFlag(Data::CapacityReserved);
834}
835
836template <typename T>
837inline void QList<T>::remove(qsizetype i, qsizetype n)
838{
839 Q_ASSERT_X(size_t(i) + size_t(n) <= size_t(d->size), "QList::remove", "index out of range");
840 Q_ASSERT_X(n >= 0, "QList::remove", "invalid count");
841
842 if (n == 0)
843 return;
844
845 d.detach();
846 d->erase(d->begin() + i, n);
847}
848
849template <typename T>
850inline void QList<T>::removeFirst() noexcept
851{
852 Q_ASSERT(!isEmpty());
853 d.detach();
854 d->eraseFirst();
855}
856
857template <typename T>
858inline void QList<T>::removeLast() noexcept
859{
860 Q_ASSERT(!isEmpty());
861 d.detach();
862 d->eraseLast();
863}
864
865
866template<typename T>
867inline T QList<T>::value(qsizetype i, parameter_type defaultValue) const
868{
869 return size_t(i) < size_t(d->size) ? at(i) : defaultValue;
870}
871
872template <typename T>
874{
875 d->growAppend(i1.i, i2.i);
876}
877
878template <typename T>
879inline void QList<T>::append(QList<T> &&other)
880{
881 Q_ASSERT(&other != this);
882 if (other.isEmpty())
883 return;
884 if (other.d->needsDetach() || !std::is_nothrow_move_constructible_v<T>)
885 return append(other);
886
887 // due to precondition &other != this, we can unconditionally modify 'this'
888 d.detachAndGrow(QArrayData::GrowsAtEnd, other.size(), nullptr, nullptr);
889 Q_ASSERT(d.freeSpaceAtEnd() >= other.size());
890 d->moveAppend(other.d->begin(), other.d->end());
891}
892
893template<typename T>
894template<typename... Args>
895inline typename QList<T>::reference QList<T>::emplaceFront(Args &&... args)
896{
897 d->emplace(0, std::forward<Args>(args)...);
898 return *d.begin();
899}
900
901
902template <typename T>
903inline typename QList<T>::iterator
904QList<T>::insert(qsizetype i, qsizetype n, parameter_type t)
905{
906 Q_ASSERT_X(size_t(i) <= size_t(d->size), "QList<T>::insert", "index out of range");
907 Q_ASSERT_X(n >= 0, "QList::insert", "invalid count");
908 if (Q_LIKELY(n))
909 d->insert(i, n, t);
910 return begin() + i;
911}
912
913template <typename T>
914template <typename ...Args>
915typename QList<T>::iterator
916QList<T>::emplace(qsizetype i, Args&&... args)
917{
918 Q_ASSERT_X(i >= 0 && i <= d->size, "QList<T>::insert", "index out of range");
919 d->emplace(i, std::forward<Args>(args)...);
920 return begin() + i;
921}
922
923template<typename T>
924template<typename... Args>
925inline typename QList<T>::reference QList<T>::emplaceBack(Args &&... args)
926{
927 d->emplace(d->size, std::forward<Args>(args)...);
928 return *(end() - 1);
929}
930
931template <typename T>
933{
934 Q_ASSERT_X(isValidIterator(abegin), "QList::erase", "The specified iterator argument 'abegin' is invalid");
935 Q_ASSERT_X(isValidIterator(aend), "QList::erase", "The specified iterator argument 'aend' is invalid");
936 Q_ASSERT(aend >= abegin);
937
938 qsizetype i = std::distance(constBegin(), abegin);
939 qsizetype n = std::distance(abegin, aend);
940 remove(i, n);
941
942 return begin() + i;
943}
944
945template <typename T>
946inline QList<T> &QList<T>::fill(parameter_type t, qsizetype newSize)
947{
948 if (newSize == -1)
949 newSize = size();
950 if (d->needsDetach() || newSize > capacity()) {
951 // must allocate memory
952 DataPointer detached(d->detachCapacity(newSize));
953 detached->copyAppend(newSize, t);
954 d.swap(detached);
955 } else {
956 // we're detached
957 const T copy(t);
958 d->assign(d.begin(), d.begin() + qMin(size(), newSize), t);
959 if (newSize > size()) {
960 d->copyAppend(newSize - size(), copy);
961 } else if (newSize < size()) {
962 d->truncate(newSize);
963 }
964 }
965 return *this;
966}
967
968namespace QtPrivate {
969template <typename T, typename U>
970qsizetype indexOf(const QList<T> &vector, const U &u, qsizetype from) noexcept
971{
972 if (from < 0)
973 from = qMax(from + vector.size(), qsizetype(0));
974 if (from < vector.size()) {
975 auto n = vector.begin() + from - 1;
976 auto e = vector.end();
977 while (++n != e)
978 if (*n == u)
979 return qsizetype(n - vector.begin());
980 }
981 return -1;
982}
983
984template <typename T, typename U>
985qsizetype lastIndexOf(const QList<T> &vector, const U &u, qsizetype from) noexcept
986{
987 if (from < 0)
988 from += vector.d->size;
989 else if (from >= vector.size())
990 from = vector.size() - 1;
991 if (from >= 0) {
992 auto b = vector.begin();
993 auto n = vector.begin() + from + 1;
994 while (n != b) {
995 if (*--n == u)
996 return qsizetype(n - b);
997 }
998 }
999 return -1;
1000}
1001}
1002
1003template <typename T>
1004template <typename AT>
1005qsizetype QListSpecialMethodsBase<T>::indexOf(const AT &t, qsizetype from) const noexcept
1006{
1007 return QtPrivate::indexOf(*self(), t, from);
1008}
1009
1010template <typename T>
1011template <typename AT>
1012qsizetype QListSpecialMethodsBase<T>::lastIndexOf(const AT &t, qsizetype from) const noexcept
1013{
1014 return QtPrivate::lastIndexOf(*self(), t, from);
1015}
1016
1017template <typename T>
1018inline QList<T> QList<T>::mid(qsizetype pos, qsizetype len) const
1019{
1020 qsizetype p = pos;
1021 qsizetype l = len;
1022 using namespace QtPrivate;
1023 switch (QContainerImplHelper::mid(d.size, &p, &l)) {
1024 case QContainerImplHelper::Null:
1025 case QContainerImplHelper::Empty:
1026 return QList();
1027 case QContainerImplHelper::Full:
1028 return *this;
1029 case QContainerImplHelper::Subset:
1030 break;
1031 }
1032
1033 // Allocate memory
1034 DataPointer copied(l);
1035 copied->copyAppend(data() + p, data() + p + l);
1036 return copied;
1037}
1038
1039Q_DECLARE_SEQUENTIAL_ITERATOR(List)
1040Q_DECLARE_MUTABLE_SEQUENTIAL_ITERATOR(List)
1041
1042template <typename T>
1043size_t qHash(const QList<T> &key, size_t seed = 0)
1044 noexcept(noexcept(qHashRange(key.cbegin(), key.cend(), seed)))
1045{
1046 return qHashRange(key.cbegin(), key.cend(), seed);
1047}
1048
1049template <typename T, typename AT>
1050qsizetype erase(QList<T> &list, const AT &t)
1051{
1052 return QtPrivate::sequential_erase(list, t);
1053}
1054
1055template <typename T, typename Predicate>
1056qsizetype erase_if(QList<T> &list, Predicate pred)
1057{
1058 return QtPrivate::sequential_erase_if(list, pred);
1059}
1060
1061// ### Qt 7 char32_t
1062QList<uint> QStringView::toUcs4() const { return QtPrivate::convertToUcs4(*this); }
1063
1064QT_END_NAMESPACE
1065
1066#include <QtCore/qbytearraylist.h>
1067#include <QtCore/qstringlist.h>
1068
1069#endif // QLIST_H
\inmodule QtCore\reentrant
Definition qdatastream.h:49
constexpr bool operator==(iterator o) const
Definition qlist.h:222
constexpr bool operator<(iterator other) const
Definition qlist.h:224
constexpr bool operator<(const_iterator other) const
Definition qlist.h:218
const_iterator operator-(qsizetype j) const
Definition qlist.h:255
constexpr bool operator==(pointer p) const
Definition qlist.h:228
constexpr bool operator>(const_iterator other) const
Definition qlist.h:220
const T & operator[](qsizetype j) const
Definition qlist.h:215
const_iterator & operator-=(qsizetype j)
Definition qlist.h:253
constexpr const_iterator(iterator o)
Definition qlist.h:212
constexpr const_iterator()=default
const T & operator*() const
Definition qlist.h:213
constexpr bool operator!=(const_iterator o) const
Definition qlist.h:217
const_iterator operator+(qsizetype j) const
Definition qlist.h:254
constexpr bool operator<=(iterator other) const
Definition qlist.h:225
const_iterator & operator++()
Definition qlist.h:230
constexpr bool operator!=(pointer p) const
Definition qlist.h:229
constexpr bool operator>(iterator other) const
Definition qlist.h:226
qsizetype operator-(const_iterator j) const
Definition qlist.h:234
constexpr bool operator==(const_iterator o) const
Definition qlist.h:216
constexpr bool operator>=(iterator other) const
Definition qlist.h:227
const_iterator operator--(int)
Definition qlist.h:233
const_iterator & operator--()
Definition qlist.h:232
const_iterator operator++(int)
Definition qlist.h:231
constexpr bool operator!=(iterator o) const
Definition qlist.h:223
const_iterator & operator+=(qsizetype j)
Definition qlist.h:252
friend const_iterator operator+(qsizetype j, const_iterator k)
Definition qlist.h:256
constexpr bool operator<=(const_iterator other) const
Definition qlist.h:219
const T * operator->() const
Definition qlist.h:214
constexpr bool operator>=(const_iterator other) const
Definition qlist.h:221
constexpr bool operator>(iterator other) const
Definition qlist.h:149
iterator operator+(qsizetype j) const
Definition qlist.h:183
iterator & operator-=(qsizetype j)
Definition qlist.h:182
T & operator[](qsizetype j) const
Definition qlist.h:144
iterator & operator++()
Definition qlist.h:159
constexpr bool operator<(const_iterator other) const
Definition qlist.h:153
constexpr bool operator!=(pointer p) const
Definition qlist.h:158
constexpr bool operator<=(iterator other) const
Definition qlist.h:148
constexpr bool operator!=(iterator o) const
Definition qlist.h:146
constexpr bool operator<=(const_iterator other) const
Definition qlist.h:154
T & operator*() const
Definition qlist.h:142
iterator operator++(int)
Definition qlist.h:160
constexpr bool operator>(const_iterator other) const
Definition qlist.h:155
constexpr bool operator>=(iterator other) const
Definition qlist.h:150
constexpr bool operator<(iterator other) const
Definition qlist.h:147
friend iterator operator+(qsizetype j, iterator k)
Definition qlist.h:185
constexpr bool operator!=(const_iterator o) const
Definition qlist.h:152
constexpr bool operator==(const_iterator o) const
Definition qlist.h:151
constexpr bool operator>=(const_iterator other) const
Definition qlist.h:156
qsizetype operator-(iterator j) const
Definition qlist.h:163
iterator & operator--()
Definition qlist.h:161
constexpr iterator()=default
T * operator->() const
Definition qlist.h:143
iterator operator-(qsizetype j) const
Definition qlist.h:184
constexpr bool operator==(iterator o) const
Definition qlist.h:145
iterator & operator+=(qsizetype j)
Definition qlist.h:181
constexpr bool operator==(pointer p) const
Definition qlist.h:157
iterator operator--(int)
Definition qlist.h:162
Definition qlist.h:80
void append(const_iterator i1, const_iterator i2)
Definition qlist.h:873
void pop_back() noexcept
Definition qlist.h:722
iterator insert(const_iterator before, parameter_type t)
Definition qlist.h:534
void removeFirst() noexcept
Definition qlist.h:850
QList< T > & fill(parameter_type t, qsizetype size=-1)
Definition qlist.h:946
const_pointer constData() const noexcept
Definition qlist.h:476
void push_front(rvalue_ref t)
Definition qlist.h:720
T & first()
Definition qlist.h:688
T & last()
Definition qlist.h:691
QList(const String &str)
Definition qlist.h:335
const_iterator begin() const noexcept
Definition qlist.h:671
bool isDetached() const noexcept
Definition qlist.h:470
void removeAt(qsizetype i)
Definition qlist.h:633
reference back()
Definition qlist.h:732
QList< T > last(qsizetype n) const
Definition qlist.h:700
bool isSharedWith(const QList< T > &other) const
Definition qlist.h:472
QList< T > & operator+=(const QList< T > &l)
Definition qlist.h:741
QList< T > operator+(const QList< T > &l) &&
Definition qlist.h:745
reference emplaceFront(Args &&... args)
Definition qlist.h:895
reference emplace_back(Args &&... args)
Definition qlist.h:726
const T & constLast() const noexcept
Definition qlist.h:693
iterator erase(const_iterator begin, const_iterator end)
Definition qlist.h:932
void resizeForOverwrite(qsizetype size)
Definition qlist.h:458
QList< T > sliced(qsizetype pos, qsizetype n) const
Definition qlist.h:704
QList(std::initializer_list< T > args)
Definition qlist.h:300
constexpr qsizetype max_size() const noexcept
Definition qlist.h:735
QTypeTraits::compare_eq_result_container< QList, U > operator==(const QList &other) const
Definition qlist.h:372
iterator insert(qsizetype i, parameter_type t)
Definition qlist.h:531
bool empty() const noexcept
Definition qlist.h:728
bool removeOne(const AT &t)
Definition qlist.h:641
QList< T > toList() const noexcept
Definition qlist.h:766
QList(InputIterator i1, InputIterator i2)
Definition qlist.h:313
static QList< T > fromReadOnlyData(const T(&t)[N]) noexcept
Definition qlist.h:772
static QList< T > fromList(const QList< T > &list) noexcept
Definition qlist.h:765
QList(qsizetype size, parameter_type t)
Definition qlist.h:293
const_reference back() const noexcept
Definition qlist.h:733
qsizetype capacity() const
Definition qlist.h:465
void swapItemsAt(qsizetype i, qsizetype j)
Definition qlist.h:710
void push_back(parameter_type t)
Definition qlist.h:718
void shrink_to_fit()
Definition qlist.h:734
QList< T > operator+(const QList< T > &l) const &
Definition qlist.h:743
void detach()
Definition qlist.h:469
const_iterator end() const noexcept
Definition qlist.h:672
iterator erase(const_iterator pos)
Definition qlist.h:685
bool endsWith(parameter_type t) const
Definition qlist.h:695
qsizetype count(const AT &t) const noexcept
Definition qlist.h:628
bool startsWith(parameter_type t) const
Definition qlist.h:694
friend qsizetype QtPrivate::lastIndexOf(const QList< V > &list, const U &u, qsizetype from) noexcept
iterator end()
Definition qlist.h:669
QList< T > operator+(QList< T > &&l) &&
Definition qlist.h:749
T takeAt(qsizetype i)
Definition qlist.h:652
const_reference at(qsizetype i) const noexcept
Definition qlist.h:489
value_type takeFirst()
Definition qlist.h:609
constexpr qsizetype size() const noexcept
Definition qlist.h:433
QList< T > sliced(qsizetype pos) const
Definition qlist.h:702
QList< T > toVector() const noexcept
Definition qlist.h:769
T value(qsizetype i) const
Definition qlist.h:707
void swap(QList &other) noexcept
Definition qlist.h:347
iterator insert(const_iterator before, qsizetype n, parameter_type t)
Definition qlist.h:539
QList< T > & operator=(std::initializer_list< T > args)
Definition qlist.h:307
void move(qsizetype from, qsizetype to)
Definition qlist.h:653
QList(DataPointer dd) noexcept
Definition qlist.h:280
const_reverse_iterator crbegin() const noexcept
Definition qlist.h:681
reference operator[](qsizetype i)
Definition qlist.h:494
const_iterator constBegin() const noexcept
Definition qlist.h:675
const_reference operator[](qsizetype i) const noexcept
Definition qlist.h:500
const_reverse_iterator rbegin() const noexcept
Definition qlist.h:679
constexpr QList() noexcept=default
void remove(qsizetype i, qsizetype n=1)
Definition qlist.h:837
value_type takeLast()
Definition qlist.h:610
const DataPointer & data_ptr() const &
Definition qlist.h:114
qsizetype removeIf(Predicate pred)
Definition qlist.h:647
reference front()
Definition qlist.h:730
DataPointer & data_ptr() &
Definition qlist.h:113
qsizetype removeAll(const AT &t)
Definition qlist.h:635
iterator emplace(qsizetype i, Args &&... args)
Definition qlist.h:916
const T & first() const noexcept
Definition qlist.h:689
iterator insert(qsizetype i, qsizetype n, parameter_type t)
Definition qlist.h:904
void append(QList< T > &&l)
Definition qlist.h:879
void squeeze()
Definition qlist.h:817
reference emplaceBack(Args &&... args)
Definition qlist.h:925
QList< T > mid(qsizetype pos, qsizetype len=-1) const
Definition qlist.h:1018
reverse_iterator rend()
Definition qlist.h:678
QTypeTraits::compare_lt_result_container< QList, U > operator>(const QList &other) const noexcept(noexcept(other< std::declval< QList< U > >()))
Definition qlist.h:402
void prepend(rvalue_ref t)
Definition qlist.h:516
QList< T > operator+(QList< T > &&l) const &
Definition qlist.h:747
QList & assign(std::initializer_list< T > l)
Definition qlist.h:569
iterator begin()
Definition qlist.h:668
void resize(qsizetype size, parameter_type c)
Definition qlist.h:452
QList< T > first(qsizetype n) const
Definition qlist.h:698
const T & constFirst() const noexcept
Definition qlist.h:690
static constexpr qsizetype maxSize()
Definition qlist.h:432
iterator emplace(const_iterator before, Args &&... args)
Definition qlist.h:573
void reserve(qsizetype size)
Definition qlist.h:796
QList & assign(InputIterator first, InputIterator last)
Definition qlist.h:566
static QList< T > fromVector(const QList< T > &vector) noexcept
Definition qlist.h:768
void replace(qsizetype i, parameter_type t)
Definition qlist.h:586
reverse_iterator rbegin()
Definition qlist.h:677
void pop_front() noexcept
Definition qlist.h:723
constexpr bool isEmpty() const noexcept
Definition qlist.h:444
pointer data()
Definition qlist.h:474
const T & last() const noexcept
Definition qlist.h:692
constexpr qsizetype count() const noexcept
Definition qlist.h:441
void removeLast() noexcept
Definition qlist.h:858
void resize(qsizetype size)
Definition qlist.h:446
friend auto compareThreeWay(const QList &lhs, const QList &rhs)
Definition qlist.h:353
const_iterator cend() const noexcept
Definition qlist.h:674
void append(parameter_type t)
Definition qlist.h:501
QList< T > & operator+=(parameter_type t)
Definition qlist.h:751
QTypeTraits::compare_eq_result_container< QList, U > operator!=(const QList &other) const
Definition qlist.h:384
const_iterator constEnd() const noexcept
Definition qlist.h:676
const_reverse_iterator rend() const noexcept
Definition qlist.h:680
T value(qsizetype i, parameter_type defaultValue) const
Definition qlist.h:867
const_iterator cbegin() const noexcept
Definition qlist.h:673
QList & assign(qsizetype n, parameter_type t)
Definition qlist.h:559
QTypeTraits::compare_lt_result_container< QList, U > operator>=(const QList &other) const noexcept(noexcept(std::declval< QList< U > >()< other))
Definition qlist.h:416
const_pointer data() const noexcept
Definition qlist.h:475
constexpr qsizetype length() const noexcept
Definition qlist.h:442
void clear()
Definition qlist.h:477
const_reference front() const noexcept
Definition qlist.h:731
QList< T > & operator+=(QList< T > &&l)
Definition qlist.h:742
friend qsizetype QtPrivate::indexOf(const QList< V > &list, const U &u, qsizetype from) noexcept
DataPointer && data_ptr() &&
Definition qlist.h:115
void append(const QList< T > &l)
Definition qlist.h:511
const_reverse_iterator crend() const noexcept
Definition qlist.h:682
Combined button and popup list for selecting options.
QString && asString(QString &&s)
Definition qstring.h:1662
constexpr QAnyStringArg qStringLikeToArg(QAnyStringView s) noexcept
Definition qstring.h:1723
qsizetype indexOf(const QList< T > &vector, const U &u, qsizetype from) noexcept
Definition qlist.h:970
const QString & asString(const QString &s)
Definition qstring.h:1661
qsizetype lastIndexOf(const QList< T > &vector, const U &u, qsizetype from) noexcept
Definition qlist.h:985
qsizetype lastIndexOf(const QList< V > &list, const U &u, qsizetype from) noexcept
qsizetype indexOf(const QList< V > &list, const U &u, qsizetype from) noexcept
static constexpr qsizetype lengthHelperPointer(const Char *data) noexcept
constexpr bool isLatin1(QLatin1StringView s) noexcept
Definition qstring.h:78
QString operator""_s(const char16_t *str, size_t size) noexcept
Definition qstring.h:1769
Definition qcompare.h:76
QByteArrayView qToByteArrayViewIgnoringNull(const QByteArrayLike &b) noexcept
Q_DECLARE_TYPEINFO(QByteArrayView, Q_PRIMITIVE_TYPE)
#define __has_cpp_attribute(x)
Q_LOGGING_CATEGORY(lcEventDispatcher, "qt.eventdispatcher")
Q_CORE_EXPORT Q_DECL_CONST_FUNCTION unsigned int qt_int_sqrt(unsigned int n)
\inmodule QtCore \title Global Qt Declarations
Definition qglobal.cpp:99
qsizetype erase(QList< T > &list, const AT &t)
Definition qlist.h:1050
QList(InputIterator, InputIterator) -> QList< ValueType >
qsizetype erase_if(QList< T > &list, Predicate pred)
Definition qlist.h:1056
QString operator+(const QString &s1, QChar s2)
Definition qstring.h:1543
QString operator+(QString &&lhs, const QString &rhs)
Definition qstring.h:1541
qsizetype erase_if(QString &s, Predicate pred)
Definition qstring.h:1761
QString operator+(QString &&lhs, QChar rhs)
Definition qstring.h:1545
QString operator+(QChar s1, const QString &s2)
Definition qstring.h:1547
QString operator+(const QString &s1, const QString &s2)
Definition qstring.h:1539
qsizetype erase(QString &s, const T &t)
Definition qstring.h:1755
QList< QList< qInternalCallback > > callbacks
Definition qglobal.cpp:128
qsizetype indexOf(const AT &t, qsizetype from=0) const noexcept
Definition qlist.h:1005
const Self * self() const
Definition qlist.h:39
bool contains(const AT &t) const noexcept
Definition qlist.h:48
QListSpecialMethodsBase()=default
qsizetype lastIndexOf(const AT &t, qsizetype from=-1) const noexcept
Definition qlist.h:1012
QListSpecialMethods()=default
constexpr QAnyStringArg(QAnyStringView v) noexcept
Definition qstring.h:1707
QAnyStringView string
Definition qstring.h:1705
QLatin1StringView string
Definition qstring.h:1699
constexpr QLatin1StringArg(QLatin1StringView v) noexcept
Definition qstring.h:1701
constexpr QStringViewArg(QStringView v) noexcept
Definition qstring.h:1695