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