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
qvarlengtharray.h
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QVARLENGTHARRAY_H
6#define QVARLENGTHARRAY_H
7
8#if 0
9#pragma qt_class(QVarLengthArray)
10#pragma qt_sync_stop_processing
11#endif
12
13#include <QtCore/qalloc.h>
14#include <QtCore/qcompare.h>
15#include <QtCore/qcontainerfwd.h>
16#include <QtCore/qglobal.h>
17#include <QtCore/qalgorithms.h>
18#include <QtCore/qcontainertools_impl.h>
19#include <QtCore/qhashfunctions.h>
20#include <QtCore/qttypetraits.h>
21
22#include <algorithm>
23#include <initializer_list>
24#include <iterator>
25#include <QtCore/q20memory.h>
26#include <new>
27
28#include <string.h>
29#include <stdlib.h>
30
31QT_BEGIN_NAMESPACE
32
33template <size_t Size, size_t Align, qsizetype Prealloc>
34class QVLAStorage
35{
36 template <size_t> class print;
37protected:
38 QVLAStorage() = default;
39 QT_DECLARE_RO5_SMF_AS_DEFAULTED(QVLAStorage)
40
41 alignas(Align) char array[Prealloc * (Align > Size ? Align : Size)];
42 QT_WARNING_PUSH
43 QT_WARNING_DISABLE_DEPRECATED
44 // ensure we maintain BC: std::aligned_storage_t was only specified by a
45 // minimum size, but for BC we need the substitution to be exact in size:
46 static_assert(std::is_same_v<print<sizeof(std::aligned_storage_t<Size, Align>[Prealloc])>,
47 print<sizeof(array)>>);
48 QT_WARNING_POP
49};
50
52{
53protected:
54 QVLABaseBase() = default;
56
57 qsizetype a; // capacity
58 qsizetype s; // size
59 void *ptr; // data
60
61 Q_ALWAYS_INLINE constexpr void verify([[maybe_unused]] qsizetype pos = 0,
62 [[maybe_unused]] qsizetype n = 1) const
63 {
64 Q_ASSERT(pos >= 0);
65 Q_ASSERT(pos <= size());
66 Q_ASSERT(n >= 0);
67 Q_ASSERT(n <= size() - pos);
68 }
69
70 struct free_deleter {
71 void operator()(void *p) const noexcept { free(p); }
72 };
73 using malloced_ptr = std::unique_ptr<void, free_deleter>;
74
75public:
77
78 constexpr size_type capacity() const noexcept { return a; }
79 constexpr size_type size() const noexcept { return s; }
80 constexpr bool empty() const noexcept { return size() == 0; }
81};
82
83template<class T>
84class QVLABase : public QVLABaseBase
85{
86protected:
87 QVLABase() = default;
89
90public:
91 T *data() noexcept { return static_cast<T *>(ptr); }
92 const T *data() const noexcept { return static_cast<T *>(ptr); }
93
94 using iterator = T*;
95 using const_iterator = const T*;
96
97 iterator begin() noexcept { return data(); }
98 const_iterator begin() const noexcept { return data(); }
99 const_iterator cbegin() const noexcept { return begin(); }
100 iterator end() noexcept { return data() + size(); }
101 const_iterator end() const noexcept { return data() + size(); }
102 const_iterator cend() const noexcept { return end(); }
103
105 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
106
107 reverse_iterator rbegin() noexcept { return reverse_iterator{end()}; }
109 const_reverse_iterator crbegin() const noexcept { return rbegin(); }
110 reverse_iterator rend() noexcept { return reverse_iterator{begin()}; }
112 const_reverse_iterator crend() const noexcept { return rend(); }
113
114 using value_type = T;
118 using const_pointer = const value_type*;
120
122 {
123 verify();
124 return *begin();
125 }
126
128 {
129 verify();
130 return *begin();
131 }
132
134 {
135 verify();
136 return *rbegin();
137 }
138
140 {
141 verify();
142 return *rbegin();
143 }
144
145 void pop_back()
146 {
147 verify();
148 if constexpr (QTypeInfo<T>::isComplex)
149 data()[size() - 1].~T();
150 --s;
151 }
152
153 template <typename AT = T>
154 qsizetype indexOf(const AT &t, qsizetype from = 0) const;
155 template <typename AT = T>
156 qsizetype lastIndexOf(const AT &t, qsizetype from = -1) const;
157 template <typename AT = T>
158 bool contains(const AT &t) const;
159
160 reference operator[](qsizetype idx)
161 {
162 verify(idx);
163 return data()[idx];
164 }
165 const_reference operator[](qsizetype idx) const
166 {
167 verify(idx);
168 return data()[idx];
169 }
170
171 value_type value(qsizetype i) const;
172 value_type value(qsizetype i, const T& defaultValue) const;
173
174 void replace(qsizetype i, const T &t);
175 void remove(qsizetype i, qsizetype n = 1);
176 void removeAt(qsizetype i) { remove(i); } // QList compatibility
177 template <typename AT = T>
178 qsizetype removeAll(const AT &t);
179 template <typename AT = T>
180 bool removeOne(const AT &t);
181 template <typename Predicate>
182 qsizetype removeIf(Predicate pred);
183
184 void clear()
185 {
186 if constexpr (QTypeInfo<T>::isComplex)
187 std::destroy_n(data(), size());
188 s = 0;
189 }
190
192 iterator erase(const_iterator pos) { return erase(pos, pos + 1); }
193
194 static constexpr qsizetype maxSize() noexcept
195 {
196 // -1 to deal with the pointer one-past-the-end
197 return (QtPrivate::MaxAllocSize / sizeof(T)) - 1;
198 }
199 constexpr qsizetype max_size() const noexcept
200 {
201 return maxSize();
202 }
203
204 size_t hash(size_t seed) const noexcept(QtPrivate::QNothrowHashable_v<T>)
205 {
206 return qHashRange(begin(), end(), seed);
207 }
208protected:
209 void growBy(qsizetype prealloc, void *array, qsizetype increment)
210 { reallocate_impl(prealloc, array, size(), (std::max)(size() * 2, size() + increment)); }
211 template <typename...Args>
212 reference emplace_back_impl(qsizetype prealloc, void *array, Args&&...args)
213 {
214 if (size() == capacity()) // ie. size() != 0
215 growBy(prealloc, array, 1);
216 reference r = *q20::construct_at(end(), std::forward<Args>(args)...);
217 ++s;
218 return r;
219 }
220 template <typename...Args>
221 iterator emplace_impl(qsizetype prealloc, void *array, const_iterator pos, Args&&...arg);
222
223 iterator insert_impl(qsizetype prealloc, void *array, const_iterator pos, qsizetype n, const T &t);
224
225 template <typename S>
226 bool equal(const QVLABase<S> &other) const
227 {
228 return std::equal(begin(), end(), other.begin(), other.end());
229 }
230 template <typename S>
231 bool less_than(const QVLABase<S> &other) const
232 {
233 return std::lexicographical_compare(begin(), end(), other.begin(), other.end());
234 }
235
236 void append_impl(qsizetype prealloc, void *array, const T *buf, qsizetype n);
237 void reallocate_impl(qsizetype prealloc, void *array, qsizetype size, qsizetype alloc);
238 void resize_impl(qsizetype prealloc, void *array, qsizetype sz, const T &v)
239 {
240 if (QtPrivate::q_points_into_range(&v, begin(), end())) {
241 resize_impl(prealloc, array, sz, T(v));
242 return;
243 }
244 reallocate_impl(prealloc, array, sz, qMax(sz, capacity()));
245 while (size() < sz) {
246 q20::construct_at(data() + size(), v);
247 ++s;
248 }
249 }
250 void resize_impl(qsizetype prealloc, void *array, qsizetype sz)
251 {
252 reallocate_impl(prealloc, array, sz, qMax(sz, capacity()));
253 if constexpr (QTypeInfo<T>::isComplex) {
254 // call default constructor for new objects (which can throw)
255 while (size() < sz) {
256 q20::construct_at(data() + size());
257 ++s;
258 }
259 } else {
260 s = sz;
261 }
262 }
263
264 void assign_impl(qsizetype prealloc, void *array, qsizetype n, const T &t);
265 template <typename Iterator>
266 void assign_impl(qsizetype prealloc, void *array, Iterator first, Iterator last,
267 std::forward_iterator_tag);
268 template <typename Iterator>
269 void assign_impl(qsizetype prealloc, void *array, Iterator first, Iterator last,
270 std::input_iterator_tag);
271 template <typename Iterator>
272 void assign_impl(qsizetype prealloc, void *array, Iterator first, Iterator last);
273
274 bool isValidIterator(const const_iterator &i) const
275 {
276 const std::less<const T *> less = {};
277 return !less(cend(), i) && !less(i, cbegin());
278 }
279};
280
281// Prealloc = 256 by default, specified in qcontainerfwd.h
282template<class T, qsizetype Prealloc>
284#if QT_VERSION >= QT_VERSION_CHECK(7,0,0) || defined(QT_BOOTSTRAPPED)
285 : public QVLAStorage<sizeof(T), alignof(T), Prealloc>,
286 public QVLABase<T>
287#else
288 : public QVLABase<T>,
289 public QVLAStorage<sizeof(T), alignof(T), Prealloc>
290#endif
291{
292 template <class S, qsizetype Prealloc2>
293 friend class QVarLengthArray;
294 using Base = QVLABase<T>;
295 using Storage = QVLAStorage<sizeof(T), alignof(T), Prealloc>;
296 static_assert(Prealloc > 0, "QVarLengthArray Prealloc must be greater than 0.");
297 static_assert(std::is_nothrow_destructible_v<T>, "Types with throwing destructors are not supported in Qt containers.");
298 using Base::verify;
299
300 template <typename U>
302 template <typename InputIterator>
304public:
305 static constexpr qsizetype PreallocatedSize = Prealloc;
306
307 using size_type = typename Base::size_type;
308 using value_type = typename Base::value_type;
309 using pointer = typename Base::pointer;
310 using const_pointer = typename Base::const_pointer;
311 using reference = typename Base::reference;
312 using const_reference = typename Base::const_reference;
313 using difference_type = typename Base::difference_type;
314
315 using iterator = typename Base::iterator;
316 using const_iterator = typename Base::const_iterator;
317 using reverse_iterator = typename Base::reverse_iterator;
319
321 {
322 this->a = Prealloc;
323 this->s = 0;
324 this->ptr = this->array;
325 }
326
327 inline explicit QVarLengthArray(qsizetype size);
328
329#ifndef Q_QDOC
330 template <typename U = T, if_copyable<U> = true>
331#endif
332 explicit QVarLengthArray(qsizetype sz, const T &v)
334 {
335 resize(sz, v);
336 }
337
340 {
341 append(other.constData(), other.size());
342 }
343
346 : Base(other)
347 {
348 const auto otherInlineStorage = reinterpret_cast<T*>(other.array);
349 if (data() == otherInlineStorage) {
350 // inline buffer - move into our inline buffer:
351 this->ptr = this->array;
352 QtPrivate::q_uninitialized_relocate_n(otherInlineStorage, size(), data());
353 } else {
354 // heap buffer - we just stole the memory
355 }
356 // reset other to internal storage:
357 other.a = Prealloc;
358 other.s = 0;
359 other.ptr = otherInlineStorage;
360 }
361
362 QVarLengthArray(std::initializer_list<T> args)
363 : QVarLengthArray(args.begin(), args.end())
364 {
365 }
366
367 template <typename InputIterator, if_input_iterator<InputIterator> = true>
368 inline QVarLengthArray(InputIterator first, InputIterator last)
370 {
371 assign(first, last);
372 }
373
375 {
376 if constexpr (QTypeInfo<T>::isComplex)
377 std::destroy_n(data(), size());
378 if (data() != reinterpret_cast<T *>(this->array))
379 QtPrivate::sizedFree(data(), capacity(), sizeof(T));
380 }
381 inline QVarLengthArray<T, Prealloc> &operator=(const QVarLengthArray<T, Prealloc> &other)
382 {
383 if (this != &other) {
384 clear();
385 append(other.constData(), other.size());
386 }
387 return *this;
388 }
389
392 {
393 // we're only required to be self-move-assignment-safe
394 // when we're in the moved-from state (Hinnant criterion)
395 // the moved-from state is the empty state, so we're good with the clear() here:
396 clear();
397 Q_ASSERT(capacity() >= Prealloc);
398 const auto thisInlineStorage = this->array;
399 const auto otherInlineStorage = other.array;
400 if (other.ptr != otherInlineStorage) {
401 // heap storage: steal the external buffer
402 if (this->ptr == thisInlineStorage) {
403 // we were using inline storage; reset other to otherInlineStorage
404 this->a = std::exchange(other.a, Prealloc);
405 this->ptr = std::exchange(other.ptr, otherInlineStorage);
406 } else {
407 // both were using heap storage; do a PURE_SWAP (note we already
408 // destroyed all elements of *this, so this is just memory, so ok!):
409 std::swap(this->a, other.a);
410 qt_ptr_swap(this->ptr, other.ptr);
411 }
412 } else {
413 // inline storage: move into our storage (doesn't matter whether inline or external)
414 QtPrivate::q_uninitialized_relocate_n(other.data(), other.size(), data());
415 }
416 this->s = std::exchange(other.s, 0);
417 return *this;
418 }
419
420 QVarLengthArray<T, Prealloc> &operator=(std::initializer_list<T> list)
421 {
422 assign(list);
423 return *this;
424 }
425
426 inline void removeLast()
427 {
428 Base::pop_back();
429 }
430#ifdef Q_QDOC
431 inline qsizetype size() const { return this->s; }
432 static constexpr qsizetype maxSize() noexcept { return QVLABase<T>::maxSize(); }
433 constexpr qsizetype max_size() const noexcept { return QVLABase<T>::max_size(); }
434#endif
435 using Base::size;
436 using Base::max_size;
437 inline qsizetype count() const { return size(); }
438 inline qsizetype length() const { return size(); }
439 inline T &first()
440 {
441 return front();
442 }
443 inline const T &first() const
444 {
445 return front();
446 }
447 T &last()
448 {
449 return back();
450 }
451 const T &last() const
452 {
453 return back();
454 }
455 bool isEmpty() const { return empty(); }
456 void resize(qsizetype sz) { Base::resize_impl(Prealloc, this->array, sz); }
457#ifndef Q_QDOC
458 template <typename U = T, if_copyable<U> = true>
459#endif
460 void resize(qsizetype sz, const T &v)
461 { Base::resize_impl(Prealloc, this->array, sz, v); }
462 using Base::clear;
463#ifdef Q_QDOC
464 inline void clear() { resize(0); }
465#endif
466 void squeeze() { reallocate(size(), size()); }
467
468 using Base::capacity;
469#ifdef Q_QDOC
470 qsizetype capacity() const { return this->a; }
471#endif
472 void reserve(qsizetype sz) { if (sz > capacity()) reallocate(size(), sz); }
473
474#ifdef Q_QDOC
475 template <typename AT = T>
476 inline qsizetype indexOf(const AT &t, qsizetype from = 0) const;
477 template <typename AT = T>
478 inline qsizetype lastIndexOf(const AT &t, qsizetype from = -1) const;
479 template <typename AT = T>
480 inline bool contains(const AT &t) const;
481#endif
482 using Base::indexOf;
483 using Base::lastIndexOf;
484 using Base::contains;
485
486#ifdef Q_QDOC
487 inline T &operator[](qsizetype idx)
488 {
489 verify(idx);
490 return data()[idx];
491 }
492 inline const T &operator[](qsizetype idx) const
493 {
494 verify(idx);
495 return data()[idx];
496 }
497#endif
498 using Base::operator[];
499 inline const T &at(qsizetype idx) const { return operator[](idx); }
500
501#ifdef Q_QDOC
502 T value(qsizetype i) const;
503 T value(qsizetype i, const T &defaultValue) const;
504#endif
505 using Base::value;
506
507 inline void append(const T &t)
508 {
509 if (size() == capacity())
510 emplace_back(T(t));
511 else
512 emplace_back(t);
513 }
514
515 void append(T &&t)
516 {
517 emplace_back(std::move(t));
518 }
519
520 void append(const T *buf, qsizetype sz)
521 { Base::append_impl(Prealloc, this->array, buf, sz); }
522 inline QVarLengthArray<T, Prealloc> &operator<<(const T &t)
523 { append(t); return *this; }
524 inline QVarLengthArray<T, Prealloc> &operator<<(T &&t)
525 { append(std::move(t)); return *this; }
526 inline QVarLengthArray<T, Prealloc> &operator+=(const T &t)
527 { append(t); return *this; }
528 inline QVarLengthArray<T, Prealloc> &operator+=(T &&t)
529 { append(std::move(t)); return *this; }
530
531#if QT_DEPRECATED_SINCE(6, 3)
532 QT_DEPRECATED_VERSION_X_6_3("This is slow. If you must, use insert(cbegin(), ~~~) instead.")
533 void prepend(T &&t);
534 QT_DEPRECATED_VERSION_X_6_3("This is slow. If you must, use insert(cbegin(), ~~~) instead.")
535 void prepend(const T &t);
536#endif
537 void insert(qsizetype i, T &&t);
538 void insert(qsizetype i, const T &t);
539 void insert(qsizetype i, qsizetype n, const T &t);
540
541 QVarLengthArray &assign(qsizetype n, const T &t)
542 { Base::assign_impl(Prealloc, this->array, n, t); return *this; }
543 template <typename InputIterator, if_input_iterator<InputIterator> = true>
544 QVarLengthArray &assign(InputIterator first, InputIterator last)
545 { Base::assign_impl(Prealloc, this->array, first, last); return *this; }
546 QVarLengthArray &assign(std::initializer_list<T> list)
547 { assign(list.begin(), list.end()); return *this; }
548
549#ifdef Q_QDOC
550 void replace(qsizetype i, const T &t);
551 void remove(qsizetype i, qsizetype n = 1);
552 void removeAt(qsizetype i);
553 template <typename AT = T>
554 qsizetype removeAll(const AT &t);
555 template <typename AT = T>
556 bool removeOne(const AT &t);
557 template <typename Predicate>
559#endif
560 using Base::replace;
561 using Base::remove;
562 using Base::removeAt;
563 using Base::removeAll;
564 using Base::removeOne;
565 using Base::removeIf;
566
567#ifdef Q_QDOC
568 inline T *data() { return this->ptr; }
569 inline const T *data() const { return this->ptr; }
570#endif
571 using Base::data;
572 inline const T *constData() const { return data(); }
573#ifdef Q_QDOC
574 inline iterator begin() { return data(); }
575 inline const_iterator begin() const { return data(); }
576 inline const_iterator cbegin() const { return begin(); }
577 inline const_iterator constBegin() const { return begin(); }
578 inline iterator end() { return data() + size(); }
579 inline const_iterator end() const { return data() + size(); }
580 inline const_iterator cend() const { return end(); }
581#endif
582
583 using Base::begin;
584 using Base::cbegin;
585 auto constBegin() const -> const_iterator { return begin(); }
586 using Base::end;
587 using Base::cend;
588 inline const_iterator constEnd() const { return end(); }
589#ifdef Q_QDOC
596#endif
597 using Base::rbegin;
598 using Base::crbegin;
599 using Base::rend;
600 using Base::crend;
601
602 iterator insert(const_iterator before, qsizetype n, const T &x)
603 { return Base::insert_impl(Prealloc, this->array, before, n, x); }
604 iterator insert(const_iterator before, T &&x) { return emplace(before, std::move(x)); }
605 inline iterator insert(const_iterator before, const T &x) { return insert(before, 1, x); }
606#ifdef Q_QDOC
608 inline iterator erase(const_iterator pos) { return erase(pos, pos + 1); }
609#endif
610 using Base::erase;
611
612 // STL compatibility:
613#ifdef Q_QDOC
614 inline bool empty() const { return isEmpty(); }
615#endif
616 using Base::empty;
617 inline void push_back(const T &t) { append(t); }
618 void push_back(T &&t) { append(std::move(t)); }
619#ifdef Q_QDOC
620 inline void pop_back() { removeLast(); }
621 inline T &front() { return first(); }
622 inline const T &front() const { return first(); }
623 inline T &back() { return last(); }
624 inline const T &back() const { return last(); }
625#endif
626 using Base::pop_back;
627 using Base::front;
628 using Base::back;
630 template <typename...Args>
631 iterator emplace(const_iterator pos, Args &&...args)
632 { return Base::emplace_impl(Prealloc, this->array, pos, std::forward<Args>(args)...); }
633 template <typename...Args>
634 T &emplace_back(Args &&...args)
635 { return Base::emplace_back_impl(Prealloc, this->array, std::forward<Args>(args)...); }
636
637
638#ifdef Q_QDOC
639 template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
640 friend inline bool operator==(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r);
641 template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
642 friend inline bool operator!=(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r);
643 template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
644 friend inline bool operator< (const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r);
645 template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
646 friend inline bool operator> (const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r);
647 template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
648 friend inline bool operator<=(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r);
649 template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
650 friend inline bool operator>=(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r);
651 template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
652 friend inline auto operator<=>(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r);
653#else
654private:
655 template <typename U = T, qsizetype Prealloc2 = Prealloc,
656 Qt::if_has_qt_compare_three_way<U, U> = true>
657 friend auto
658 compareThreeWay(const QVarLengthArray &lhs, const QVarLengthArray<T, Prealloc2> &rhs)
659 {
660 return QtOrderingPrivate::lexicographicalCompareThreeWay(lhs.begin(), lhs.end(),
661 rhs.begin(), rhs.end());
662 }
663
664#if defined(__cpp_lib_three_way_comparison) && defined(__cpp_lib_concepts)
665 template <typename U = T, qsizetype Prealloc2 = Prealloc,
667 friend auto
669 {
671 rhs.begin(), rhs.end(),
673 }
674#endif // __cpp_lib_three_way_comparison && __cpp_lib_concepts
675
676public:
677 template <typename U = T, qsizetype Prealloc2 = Prealloc> friend
678 QTypeTraits::compare_eq_result<U> operator==(const QVarLengthArray<T, Prealloc> &l, const QVarLengthArray<T, Prealloc2> &r)
679 {
680 return l.equal(r);
681 }
682
683 template <typename U = T, qsizetype Prealloc2 = Prealloc> friend
684 QTypeTraits::compare_eq_result<U> operator!=(const QVarLengthArray<T, Prealloc> &l, const QVarLengthArray<T, Prealloc2> &r)
685 {
686 return !(l == r);
687 }
688
689#ifndef __cpp_lib_three_way_comparison
690 template <typename U = T, qsizetype Prealloc2 = Prealloc> friend
691 QTypeTraits::compare_lt_result<U> operator<(const QVarLengthArray<T, Prealloc> &lhs, const QVarLengthArray<T, Prealloc2> &rhs)
692 noexcept(noexcept(std::lexicographical_compare(lhs.begin(), lhs.end(),
693 rhs.begin(), rhs.end())))
694 {
695 return lhs.less_than(rhs);
696 }
697
698 template <typename U = T, qsizetype Prealloc2 = Prealloc> friend
699 QTypeTraits::compare_lt_result<U> operator>(const QVarLengthArray<T, Prealloc> &lhs, const QVarLengthArray<T, Prealloc2> &rhs)
700 noexcept(noexcept(lhs < rhs))
701 {
702 return rhs < lhs;
703 }
704
705 template <typename U = T, qsizetype Prealloc2 = Prealloc> friend
706 QTypeTraits::compare_lt_result<U> operator<=(const QVarLengthArray<T, Prealloc> &lhs, const QVarLengthArray<T, Prealloc2> &rhs)
707 noexcept(noexcept(lhs < rhs))
708 {
709 return !(lhs > rhs);
710 }
711
712 template <typename U = T, qsizetype Prealloc2 = Prealloc> friend
713 QTypeTraits::compare_lt_result<U> operator>=(const QVarLengthArray<T, Prealloc> &lhs, const QVarLengthArray<T, Prealloc2> &rhs)
714 noexcept(noexcept(lhs < rhs))
715 {
716 return !(lhs < rhs);
717 }
718#endif // __cpp_lib_three_way_comparison
719#endif // Q_QDOC
720
721private:
722 template <typename U, qsizetype Prealloc2>
723 bool equal(const QVarLengthArray<U, Prealloc2> &other) const
724 { return Base::equal(other); }
725 template <typename U, qsizetype Prealloc2>
726 bool less_than(const QVarLengthArray<U, Prealloc2> &other) const
727 { return Base::less_than(other); }
728
729 void reallocate(qsizetype sz, qsizetype alloc)
730 { Base::reallocate_impl(Prealloc, this->array, sz, alloc); }
731
732 using Base::isValidIterator;
733};
734
735template <typename InputIterator,
736 typename ValueType = typename std::iterator_traits<InputIterator>::value_type,
737 QtPrivate::IfIsInputIterator<InputIterator> = true>
738QVarLengthArray(InputIterator, InputIterator) -> QVarLengthArray<ValueType>;
739
740template <class T, qsizetype Prealloc>
741Q_INLINE_TEMPLATE QVarLengthArray<T, Prealloc>::QVarLengthArray(qsizetype asize)
742 : QVarLengthArray()
743{
744 Q_ASSERT_X(asize >= 0, "QVarLengthArray::QVarLengthArray(qsizetype)",
745 "Size must be greater than or equal to 0.");
746
747 // historically, this ctor worked for non-copyable/non-movable T, so keep it working, why not?
748 // resize(asize) // this requires a movable or copyable T, can't use, need to do it by hand
749
750 if (asize > Prealloc) {
751 this->a = asize;
752 this->ptr = QtPrivate::fittedMalloc(0, &this->a, sizeof(T));
753 Q_CHECK_PTR(this->ptr);
754 }
755 if constexpr (QTypeInfo<T>::isComplex)
756 std::uninitialized_default_construct_n(data(), asize);
757 this->s = asize;
758}
759
760template <class T>
761template <typename AT>
762Q_INLINE_TEMPLATE qsizetype QVLABase<T>::indexOf(const AT &t, qsizetype from) const
763{
764 if (from < 0)
765 from = qMax(from + size(), qsizetype(0));
766 if (from < size()) {
767 const T *n = data() + from - 1;
768 const T *e = end();
769 while (++n != e)
770 if (*n == t)
771 return n - data();
772 }
773 return -1;
774}
775
776template <class T>
777template <typename AT>
778Q_INLINE_TEMPLATE qsizetype QVLABase<T>::lastIndexOf(const AT &t, qsizetype from) const
779{
780 if (from < 0)
781 from += size();
782 else if (from >= size())
783 from = size() - 1;
784 if (from >= 0) {
785 const T *b = begin();
786 const T *n = b + from + 1;
787 while (n != b) {
788 if (*--n == t)
789 return n - b;
790 }
791 }
792 return -1;
793}
794
795template <class T>
796template <typename AT>
797Q_INLINE_TEMPLATE bool QVLABase<T>::contains(const AT &t) const
798{
799 const T *b = begin();
800 const T *i = end();
801 while (i != b) {
802 if (*--i == t)
803 return true;
804 }
805 return false;
806}
807
808template <class T>
809Q_OUTOFLINE_TEMPLATE void QVLABase<T>::append_impl(qsizetype prealloc, void *array, const T *abuf, qsizetype increment)
810{
811 Q_ASSERT(abuf || increment == 0);
812 if (increment <= 0)
813 return;
814
815 const qsizetype asize = size() + increment;
816
817 if (asize >= capacity())
818 growBy(prealloc, array, increment);
819
820 if constexpr (QTypeInfo<T>::isComplex)
821 std::uninitialized_copy_n(abuf, increment, end());
822 else
823 memcpy(static_cast<void *>(end()), static_cast<const void *>(abuf), increment * sizeof(T));
824
825 this->s = asize;
826}
827
828template <class T>
829Q_OUTOFLINE_TEMPLATE void QVLABase<T>::assign_impl(qsizetype prealloc, void *array, qsizetype n, const T &t)
830{
831 Q_ASSERT(n >= 0);
832 if (n > capacity()) {
833 reallocate_impl(prealloc, array, 0, capacity()); // clear
834 resize_impl(prealloc, array, n, t);
835 } else {
836 auto mid = (std::min)(n, size());
837 std::fill(data(), data() + mid, t);
838 std::uninitialized_fill(data() + mid, data() + n, t);
839 s = n;
840 erase(data() + n, data() + size());
841 }
842}
843
844template <class T>
845template <typename Iterator>
847void QVLABase<T>::assign_impl(qsizetype prealloc, void *array, Iterator first, Iterator last,
848 std::forward_iterator_tag)
849{
850 // This function only provides the basic exception guarantee.
851 const qsizetype n = std::distance(first, last);
852 if (n > capacity())
853 reallocate_impl(prealloc, array, 0, n); // clear & reserve n
854
855 auto dst = begin();
856
857 if constexpr (!QTypeInfo<T>::isComplex) {
858 // For non-complex types, we prefer a single std::copy() -> memcpy()
859 // call. We can do that because either the default constructor is
860 // trivial (so the lifetime has started) or the copy constructor is
861 // (and won't care what the stored value is). Note that in some cases
862 // dst > end() after this.
863 dst = std::copy(first, last, dst);
864 } else if (n > this->s) {
865 // overwrite existing elements and create new
866 for (qsizetype i = 0; i < this->s; ++i) {
867 *dst = *first;
868 ++first;
869 ++dst;
870 }
871 std::uninitialized_copy_n(first, n - this->s, dst);
872 } else {
873 // overwrite existing elements and destroy tail
874 dst = std::copy(first, last, dst);
875 std::destroy(dst, end());
876 }
877 this->s = n;
878}
879
880template <class T>
881template <typename Iterator>
883void QVLABase<T>::assign_impl(qsizetype prealloc, void *array, Iterator first, Iterator last,
884 std::input_iterator_tag)
885{
886 // This function only provides the basic exception guarantee.
887 auto dst = begin();
888 const auto dend = end();
889 while (true) {
890 if (first == last) { // ran out of elements to assign
891 std::destroy(dst, dend);
892 break;
893 }
894 if (dst == dend) { // ran out of existing elements to overwrite
895 do {
896 emplace_back_impl(prealloc, array, *first);
897 } while (++first != last);
898 return; // size() is already correct (and dst invalidated)!
899 }
900 *dst = *first; // overwrite existing element
901 ++dst;
902 ++first;
903 }
904 this->s = dst - begin();
905}
906
907template <class T>
908template <typename Iterator>
910void QVLABase<T>::assign_impl(qsizetype prealloc, void *array, Iterator first, Iterator last)
911{
912 using Cat = typename std::iterator_traits<Iterator>::iterator_category;
913 assign_impl(prealloc, array, first, last, Cat{});
914}
915
916template <class T>
917Q_OUTOFLINE_TEMPLATE void QVLABase<T>::reallocate_impl(qsizetype prealloc, void *array, qsizetype asize, qsizetype aalloc)
918{
919 Q_ASSERT(aalloc >= asize);
920 Q_ASSERT(data());
921 T *oldPtr = data();
922 qsizetype osize = size();
923 const qsizetype oalloc = capacity();
924
925 const qsizetype copySize = qMin(asize, osize);
926 Q_ASSERT(copySize >= 0);
927
928 if (aalloc != oalloc) {
930 void *newPtr;
931 qsizetype newA;
932 if (aalloc > prealloc) {
933 newPtr = QtPrivate::fittedMalloc(0, &aalloc, sizeof(T));
934 guard.reset(newPtr);
935 Q_CHECK_PTR(newPtr); // could throw
936 // by design: in case of QT_NO_EXCEPTIONS malloc must not fail or it crashes here
937 newA = aalloc;
938 } else {
939 newPtr = array;
940 newA = prealloc;
941 }
942 QtPrivate::q_uninitialized_relocate_n(oldPtr, copySize,
943 reinterpret_cast<T *>(newPtr));
944 // commit:
945 ptr = newPtr;
946 guard.release();
947 a = newA;
948 }
949 s = copySize;
950
951 // destroy remaining old objects
952 if constexpr (QTypeInfo<T>::isComplex) {
953 if (osize > asize)
954 std::destroy(oldPtr + asize, oldPtr + osize);
955 }
956
957 if (oldPtr != reinterpret_cast<T *>(array) && oldPtr != data())
958 QtPrivate::sizedFree(oldPtr, oalloc, sizeof(T));
959}
960
961template <class T>
962Q_OUTOFLINE_TEMPLATE T QVLABase<T>::value(qsizetype i) const
963{
964 if (size_t(i) >= size_t(size()))
965 return T();
966 return operator[](i);
967}
968template <class T>
969Q_OUTOFLINE_TEMPLATE T QVLABase<T>::value(qsizetype i, const T &defaultValue) const
970{
971 return (size_t(i) >= size_t(size())) ? defaultValue : operator[](i);
972}
973
974template <class T, qsizetype Prealloc>
975inline void QVarLengthArray<T, Prealloc>::insert(qsizetype i, T &&t)
976{ verify(i, 0);
977 insert(cbegin() + i, std::move(t)); }
978template <class T, qsizetype Prealloc>
979inline void QVarLengthArray<T, Prealloc>::insert(qsizetype i, const T &t)
980{ verify(i, 0);
981 insert(begin() + i, 1, t); }
982template <class T, qsizetype Prealloc>
983inline void QVarLengthArray<T, Prealloc>::insert(qsizetype i, qsizetype n, const T &t)
984{ verify(i, 0);
985 insert(begin() + i, n, t); }
986template <class T>
987inline void QVLABase<T>::remove(qsizetype i, qsizetype n)
988{ verify(i, n);
989 erase(begin() + i, begin() + i + n); }
990template <class T>
991template <typename AT>
992inline qsizetype QVLABase<T>::removeAll(const AT &t)
993{ return QtPrivate::sequential_erase_with_copy(*this, t); }
994template <class T>
995template <typename AT>
996inline bool QVLABase<T>::removeOne(const AT &t)
997{ return QtPrivate::sequential_erase_one(*this, t); }
998template <class T>
999template <typename Predicate>
1000inline qsizetype QVLABase<T>::removeIf(Predicate pred)
1001{ return QtPrivate::sequential_erase_if(*this, pred); }
1002#if QT_DEPRECATED_SINCE(6, 3)
1003template <class T, qsizetype Prealloc>
1004inline void QVarLengthArray<T, Prealloc>::prepend(T &&t)
1005{ insert(cbegin(), std::move(t)); }
1006template <class T, qsizetype Prealloc>
1007inline void QVarLengthArray<T, Prealloc>::prepend(const T &t)
1008{ insert(begin(), 1, t); }
1009#endif
1010
1011template <class T>
1012inline void QVLABase<T>::replace(qsizetype i, const T &t)
1013{
1014 verify(i);
1015 data()[i] = t;
1016}
1017
1018template <class T>
1019template <typename...Args>
1020Q_OUTOFLINE_TEMPLATE auto QVLABase<T>::emplace_impl(qsizetype prealloc, void *array, const_iterator before, Args &&...args) -> iterator
1021{
1022 Q_ASSERT_X(isValidIterator(before), "QVarLengthArray::insert", "The specified const_iterator argument 'before' is invalid");
1023 Q_ASSERT(size() <= capacity());
1024 Q_ASSERT(capacity() > 0);
1025
1026 const qsizetype offset = qsizetype(before - cbegin());
1027 emplace_back_impl(prealloc, array, std::forward<Args>(args)...);
1028 const auto b = begin() + offset;
1029 const auto e = end();
1030 QtPrivate::q_rotate(b, e - 1, e);
1031 return b;
1032}
1033
1034template <class T>
1035Q_OUTOFLINE_TEMPLATE auto QVLABase<T>::insert_impl(qsizetype prealloc, void *array, const_iterator before, qsizetype n, const T &t) -> iterator
1036{
1037 Q_ASSERT_X(isValidIterator(before), "QVarLengthArray::insert", "The specified const_iterator argument 'before' is invalid");
1038
1039 const qsizetype offset = qsizetype(before - cbegin());
1040 resize_impl(prealloc, array, size() + n, t);
1041 const auto b = begin() + offset;
1042 const auto e = end();
1043 QtPrivate::q_rotate(b, e - n, e);
1044 return b;
1045}
1046
1047template <class T>
1049{
1050 Q_ASSERT_X(isValidIterator(abegin), "QVarLengthArray::erase", "The specified const_iterator argument 'abegin' is invalid");
1051 Q_ASSERT_X(isValidIterator(aend), "QVarLengthArray::erase", "The specified const_iterator argument 'aend' is invalid");
1052
1053 qsizetype f = qsizetype(abegin - cbegin());
1054 qsizetype l = qsizetype(aend - cbegin());
1055 qsizetype n = l - f;
1056
1057 if (n == 0) // avoid UB in std::move() below
1058 return data() + f;
1059
1060 Q_ASSERT(n > 0); // aend must be reachable from abegin
1061
1062 if constexpr (!QTypeInfo<T>::isRelocatable) {
1063 std::move(begin() + l, end(), QT_MAKE_CHECKED_ARRAY_ITERATOR(begin() + f, size() - f));
1064 std::destroy(end() - n, end());
1065 } else {
1066 std::destroy(abegin, aend);
1067 memmove(static_cast<void *>(data() + f), static_cast<const void *>(data() + l), (size() - l) * sizeof(T));
1068 }
1069 this->s -= n;
1070 return data() + f;
1071}
1072
1073#ifdef Q_QDOC
1074// Fake definitions for qdoc, only the redeclaration is used.
1075template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
1076bool operator==(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r)
1077{ return bool{}; }
1078template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
1079bool operator!=(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r)
1080{ return bool{}; }
1081template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
1082bool operator< (const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r)
1083{ return bool{}; }
1084template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
1085bool operator> (const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r)
1086{ return bool{}; }
1087template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
1088bool operator<=(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r)
1089{ return bool{}; }
1090template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
1091bool operator>=(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r)
1092{ return bool{}; }
1093#endif
1094
1095template <typename T, qsizetype Prealloc>
1096size_t qHash(const QVarLengthArray<T, Prealloc> &key, size_t seed = 0)
1097 noexcept(QtPrivate::QNothrowHashable_v<T>)
1098{
1099 return key.hash(seed);
1100}
1101
1102template <typename T, qsizetype Prealloc, typename AT>
1103qsizetype erase(QVarLengthArray<T, Prealloc> &array, const AT &t)
1104{
1105 return array.removeAll(t);
1106}
1107
1108template <typename T, qsizetype Prealloc, typename Predicate>
1109qsizetype erase_if(QVarLengthArray<T, Prealloc> &array, Predicate pred)
1110{
1111 return array.removeIf(pred);
1112}
1113
1114QT_END_NAMESPACE
1115
1116#endif // QVARLENGTHARRAY_H
QByteArray::Base64DecodingStatus decodingStatus
Definition qbytearray.h:788
friend bool operator==(const QByteArray::FromBase64Result &lhs, const QByteArray::FromBase64Result &rhs) noexcept
Returns true if lhs and rhs are equal, otherwise returns false.
Definition qbytearray.h:802
QByteArray & operator*() &noexcept
Definition qbytearray.h:798
const QByteArray & operator*() const &noexcept
Definition qbytearray.h:799
void swap(QByteArray::FromBase64Result &other) noexcept
Definition qbytearray.h:790
operator bool() const noexcept
\variable QByteArray::FromBase64Result::decoded
Definition qbytearray.h:796
QByteArray && operator*() &&noexcept
Definition qbytearray.h:800
friend bool operator!=(const QByteArray::FromBase64Result &lhs, const QByteArray::FromBase64Result &rhs) noexcept
Returns true if lhs and rhs are different, otherwise returns false.
Definition qbytearray.h:813
\inmodule QtCore
Definition qbytearray.h:58
\inmodule QtCore\reentrant
Definition qdatastream.h:50
\inmodule QtCore
Definition qeventloop.h:60
int initFrom(const QMessageLogContext &logContext)
void populateBacktrace(int frameCount)
QInternalMessageLogContext(const QMessageLogContext &logContext, const QLoggingCategory &categoryOverride)
Definition qlogging_p.h:66
std::optional< BacktraceStorage > backtrace
Definition qlogging_p.h:58
static constexpr int DefaultBacktraceDepth
Definition qlogging_p.h:48
Definition qlist.h:81
\inmodule QtCore
Definition qlogging.h:44
constexpr QMessageLogContext(const char *fileName, int lineNumber, const char *functionName, const char *categoryName) noexcept
Definition qlogging.h:49
const char * category
Definition qlogging.h:56
constexpr QMessageLogContext() noexcept=default
const char * function
Definition qlogging.h:55
const char * file
Definition qlogging.h:54
\inmodule QtCore
Definition qlogging.h:74
QDebug debug(CategoryFunction catFunc) const
QDebug debug(const QLoggingCategory &cat) const
Logs a debug message into category cat using a QDebug stream.
Definition qlogging.cpp:526
void void void void Q_DECL_COLD_FUNCTION void Q_DECL_COLD_FUNCTION void Q_DECL_COLD_FUNCTION void Q_DECL_COLD_FUNCTION void QT_MESSAGE_LOGGER_NORETURN Q_DECL_COLD_FUNCTION void QT_MESSAGE_LOGGER_NORETURN Q_DECL_COLD_FUNCTION void QDebug debug() const
Logs a debug message using a QDebug stream.
Definition qlogging.cpp:512
QDebug info(const QLoggingCategory &cat) const
Logs an informational message into the category cat using a QDebug stream.
Definition qlogging.cpp:615
QDebug info() const
Logs an informational message using a QDebug stream.
Definition qlogging.cpp:601
QNoDebug noDebug(...) const noexcept
QDebug info(CategoryFunction catFunc) const
\inmodule QtCore
Definition qmutex.h:346
Mutex * mutex() const noexcept
Returns the mutex on which the QMutexLocker is operating.
Definition qmutex.h:354
void unlock() noexcept
Unlocks this mutex locker.
Definition qmutex.h:352
~QMutexLocker() noexcept
Destroys the QMutexLocker and unlocks the mutex that was locked in the constructor.
Definition qmutex.h:350
void relock() noexcept
Relocks an unlocked mutex locker.
Definition qmutex.h:353
\inmodule QtCore
Definition qmutex.h:342
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:177
constexpr size_type capacity() const noexcept
Q_ALWAYS_INLINE constexpr void verify(qsizetype pos=0, qsizetype n=1) const
constexpr bool empty() const noexcept
QVLABaseBase()=default
std::unique_ptr< void, free_deleter > malloced_ptr
constexpr size_type size() const noexcept
value_type value(qsizetype i, const T &defaultValue) const
const_reverse_iterator rend() const noexcept
void remove(qsizetype i, qsizetype n=1)
void reallocate_impl(qsizetype prealloc, void *array, qsizetype size, qsizetype alloc)
const_reference operator[](qsizetype idx) const
value_type value(qsizetype i) const
const_reverse_iterator rbegin() const noexcept
reference emplace_back_impl(qsizetype prealloc, void *array, Args &&...args)
bool less_than(const QVLABase< S > &other) const
qsizetype removeIf(Predicate pred)
iterator erase(const_iterator pos)
const_reference back() const
reverse_iterator rbegin() noexcept
const_iterator cbegin() const noexcept
qsizetype lastIndexOf(const AT &t, qsizetype from=-1) const
value_type & reference
void resize_impl(qsizetype prealloc, void *array, qsizetype sz, const T &v)
void growBy(qsizetype prealloc, void *array, qsizetype increment)
bool removeOne(const AT &t)
bool equal(const QVLABase< S > &other) const
void assign_impl(qsizetype prealloc, void *array, Iterator first, Iterator last, std::forward_iterator_tag)
void pop_back()
reference front()
iterator erase(const_iterator begin, const_iterator end)
const_reference front() const
bool isValidIterator(const const_iterator &i) const
const_iterator cend() const noexcept
static constexpr qsizetype maxSize() noexcept
const value_type * const_pointer
const_reverse_iterator crbegin() const noexcept
std::reverse_iterator< const_iterator > const_reverse_iterator
iterator end() noexcept
void resize_impl(qsizetype prealloc, void *array, qsizetype sz)
void replace(qsizetype i, const T &t)
iterator insert_impl(qsizetype prealloc, void *array, const_iterator pos, qsizetype n, const T &t)
Q_OUTOFLINE_TEMPLATE void assign_impl(qsizetype prealloc, void *array, Iterator first, Iterator last, std::input_iterator_tag)
void assign_impl(qsizetype prealloc, void *array, Iterator first, Iterator last, std::input_iterator_tag)
void assign_impl(qsizetype prealloc, void *array, Iterator first, Iterator last)
Q_OUTOFLINE_TEMPLATE void assign_impl(qsizetype prealloc, void *array, Iterator first, Iterator last, std::forward_iterator_tag)
reference operator[](qsizetype idx)
size_t hash(size_t seed) const noexcept(QtPrivate::QNothrowHashable_v< T >)
Q_OUTOFLINE_TEMPLATE void assign_impl(qsizetype prealloc, void *array, Iterator first, Iterator last)
const_iterator end() const noexcept
qsizetype indexOf(const AT &t, qsizetype from=0) const
QVLABase()=default
const_iterator begin() const noexcept
void removeAt(qsizetype i)
qsizetype removeAll(const AT &t)
const value_type & const_reference
const T * const_iterator
Q_INLINE_TEMPLATE bool contains(const AT &t) const
value_type * pointer
void append_impl(qsizetype prealloc, void *array, const T *buf, qsizetype n)
const_reverse_iterator crend() const noexcept
bool contains(const AT &t) const
reverse_iterator rend() noexcept
constexpr qsizetype max_size() const noexcept
reference back()
void assign_impl(qsizetype prealloc, void *array, qsizetype n, const T &t)
iterator begin() noexcept
iterator emplace_impl(qsizetype prealloc, void *array, const_iterator pos, Args &&...arg)
bool isEmpty() const
friend QTypeTraits::compare_lt_result< U > operator>(const QVarLengthArray< T, Prealloc > &lhs, const QVarLengthArray< T, Prealloc2 > &rhs) noexcept(noexcept(lhs< rhs))
QVarLengthArray & assign(InputIterator first, InputIterator last)
QVarLengthArray< T, Prealloc > & operator+=(const T &t)
iterator insert(const_iterator before, T &&x)
const T & first() const
typename Base::pointer pointer
T & emplace_back(Args &&...args)
const T & at(qsizetype idx) const
void resize(qsizetype sz)
QVarLengthArray< T, Prealloc > & operator=(const QVarLengthArray< T, Prealloc > &other)
typename Base::iterator iterator
qsizetype count() const
typename Base::const_pointer const_pointer
void push_back(T &&t)
QVarLengthArray(qsizetype sz, const T &v)
QVarLengthArray(const QVarLengthArray &other)
QVarLengthArray(qsizetype size)
iterator insert(const_iterator before, qsizetype n, const T &x)
QVarLengthArray(InputIterator first, InputIterator last)
iterator emplace(const_iterator pos, Args &&...args)
typename Base::reference reference
typename Base::size_type size_type
void insert(qsizetype i, T &&t)
QVarLengthArray(QVarLengthArray &&other) noexcept(std::is_nothrow_move_constructible_v< T >)
friend QTypeTraits::compare_lt_result< U > operator<=(const QVarLengthArray< T, Prealloc > &lhs, const QVarLengthArray< T, Prealloc2 > &rhs) noexcept(noexcept(lhs< rhs))
const T & last() const
QVarLengthArray & operator=(QVarLengthArray &&other) noexcept(std::is_nothrow_move_constructible_v< T >)
static constexpr qsizetype PreallocatedSize
friend QTypeTraits::compare_eq_result< U > operator==(const QVarLengthArray< T, Prealloc > &l, const QVarLengthArray< T, Prealloc2 > &r)
typename Base::const_iterator const_iterator
QVarLengthArray & assign(qsizetype n, const T &t)
QVarLengthArray< T, Prealloc > & operator+=(T &&t)
const_iterator constEnd() const
friend QTypeTraits::compare_eq_result< U > operator!=(const QVarLengthArray< T, Prealloc > &l, const QVarLengthArray< T, Prealloc2 > &r)
friend QTypeTraits::compare_lt_result< U > operator>=(const QVarLengthArray< T, Prealloc > &lhs, const QVarLengthArray< T, Prealloc2 > &rhs) noexcept(noexcept(lhs< rhs))
typename Base::value_type value_type
void resize(qsizetype sz, const T &v)
typename Base::const_reference const_reference
typename Base::difference_type difference_type
void append(const T *buf, qsizetype sz)
QVarLengthArray< T, Prealloc > & operator=(std::initializer_list< T > list)
friend auto compareThreeWay(const QVarLengthArray &lhs, const QVarLengthArray< T, Prealloc2 > &rhs)
QVarLengthArray(std::initializer_list< T > args)
qsizetype length() const
iterator insert(const_iterator before, const T &x)
friend QTypeTraits::compare_lt_result< U > operator<(const QVarLengthArray< T, Prealloc > &lhs, const QVarLengthArray< T, Prealloc2 > &rhs) noexcept(noexcept(std::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end())))
typename Base::reverse_iterator reverse_iterator
void insert(qsizetype i, const T &t)
void append(const T &t)
const T * constData() const
typename Base::const_reverse_iterator const_reverse_iterator
void push_back(const T &t)
auto constBegin() const -> const_iterator
QVarLengthArray() noexcept
void reserve(qsizetype sz)
QVarLengthArray & assign(std::initializer_list< T > list)
void insert(qsizetype i, qsizetype n, const T &t)
static const char ifCriticalTokenC[]
static bool grabMessageHandler()
void qt_message_output(QtMsgType msgType, const QMessageLogContext &context, const QString &message)
static const char emptyTokenC[]
static Q_NEVER_INLINE void qt_message(QtMsgType msgType, const QMessageLogContext &context, const char *msg, va_list ap)
Definition qlogging.cpp:409
static void preformattedMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &formattedMessage)
static bool systemHasStderr()
Returns true if writing to stderr is supported.
Definition qlogging.cpp:263
static const char endifTokenC[]
static bool isDefaultCategory(const char *category)
Definition qlogging.cpp:955
static const char messageTokenC[]
static bool qt_append_thread_name_to(QString &message)
Definition qlogging.cpp:248
static constexpr SystemMessageSink systemMessageSink
static void qt_maybe_message_fatal(QtMsgType, const QMessageLogContext &context, String &&message)
\inmodule QtCore \title Qt Logging Types
#define HANDLE_IF_TOKEN(LEVEL)
Q_DECLARE_TYPEINFO(QMessagePattern::BacktraceParams, Q_RELOCATABLE_TYPE)
static void qDefaultMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &buf)
static const char timeTokenC[]
static bool isFatalCountDown(const char *varname, QBasicAtomicInt &n)
Definition qlogging.cpp:153
void qErrnoWarning(int code, const char *msg,...)
static const char qthreadptrTokenC[]
static const char fileTokenC[]
static const char ifDebugTokenC[]
static const char ifFatalTokenC[]
static const char categoryTokenC[]
static void stderr_message_handler(QtMsgType type, const QMessageLogContext &context, const QString &formattedMessage)
static const char lineTokenC[]
static const char typeTokenC[]
static void ungrabMessageHandler()
static void copyInternalContext(QInternalMessageLogContext *self, const QMessageLogContext &logContext) noexcept
static const char ifCategoryTokenC[]
static int checked_var_value(const char *varname)
Definition qlogging.cpp:139
static const char threadnameTokenC[]
static const char pidTokenC[]
Q_TRACE_POINT(qtcore, qt_message_print, int type, const char *category, const char *function, const char *file, int line, const QString &message)
static const char threadidTokenC[]
static QString formatLogMessage(QtMsgType type, const QMessageLogContext &context, const QString &str)
static Q_CONSTINIT bool msgHandlerGrabbed
static const char backtraceTokenC[]
void qErrnoWarning(const char *msg,...)
static const char functionTokenC[]
#define IF_TOKEN(LEVEL)
static const char ifWarningTokenC[]
static const char appnameTokenC[]
static bool isFatal(QtMsgType msgType)
Definition qlogging.cpp:187
static const char ifInfoTokenC[]
QtMessageHandler qInstallMessageHandler(QtMessageHandler h)
static void qt_message_print(QtMsgType, const QMessageLogContext &context, const QString &message)
static bool stderrHasConsoleAttached()
Returns true if writing to stderr will end up in a console/terminal visible to the user.
Definition qlogging.cpp:288
void qSetMessagePattern(const QString &pattern)
Combined button and popup list for selecting options.
QDebug printAssociativeContainer(QDebug debug, const char *which, const AssociativeContainer &c)
Definition qdebug.h:385
bool shouldLogToStderr()
Returns true if logging stderr should be ensured.
Definition qlogging.cpp:341
QDebug printSequentialContainer(QDebug debug, const char *which, const SequentialContainer &c)
Definition qdebug.h:367
QByteArray operator""_ba(const char *str, size_t size) noexcept
Definition qbytearray.h:848
Definition qcompare.h:111
QT_BEGIN_NAMESPACE Q_NORETURN void qAbort()
Definition qassert.cpp:25
QByteArray operator+(const QByteArray &a1, const char *a2)
Definition qbytearray.h:709
QByteArray qUncompress(const QByteArray &data)
Definition qbytearray.h:778
QByteArray operator+(char a1, const QByteArray &a2)
Definition qbytearray.h:719
QByteArray operator+(QByteArray &&lhs, char rhs)
Definition qbytearray.h:715
QByteArray operator+(const QByteArray &a1, char a2)
Definition qbytearray.h:713
QByteArray operator+(const char *a1, const QByteArray &a2)
Definition qbytearray.h:717
QByteArray operator+(QByteArray &&lhs, const QByteArray &rhs)
Definition qbytearray.h:707
qsizetype erase_if(QByteArray &ba, Predicate pred)
Definition qbytearray.h:831
QByteArray operator+(const QByteArray &a1, const QByteArray &a2)
Definition qbytearray.h:705
QByteArray qCompress(const QByteArray &data, int compressionLevel=-1)
Definition qbytearray.h:776
#define QT5_NULL_STRINGS
Definition qbytearray.h:26
qsizetype erase(QByteArray &ba, const T &t)
Definition qbytearray.h:825
QByteArray operator+(QByteArray &&lhs, const char *rhs)
Definition qbytearray.h:711
#define __has_builtin(x)
#define __has_include(x)
void qt_QMetaEnum_flagDebugOperator(QDebug &debug, size_t sizeofT, Int value)
Definition qdebug.h:614
Q_CORE_EXPORT void qt_QMetaEnum_flagDebugOperator(QDebug &debug, size_t sizeofT, quint64 value)
Definition qdebug.cpp:1444
Q_CORE_EXPORT void qt_QMetaEnum_flagDebugOperator(QDebug &debug, size_t sizeofT, uint value)
Definition qdebug.cpp:1435
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition qdir.cpp:2582
#define QT_MESSAGELOG_FUNC
Definition qlogging.h:162
#define QT_MESSAGELOG_FILE
Definition qlogging.h:160
#define QT_MESSAGE_LOGGER_NORETURN
Definition qlogging.h:70
#define QT_MESSAGELOG_LINE
Definition qlogging.h:161
Q_CORE_EXPORT void qSetMessagePattern(const QString &messagePattern)
#define QT_MESSAGELOGCONTEXT
Definition qlogging.h:155
QtMsgType
Definition qlogging.h:30
@ QtCriticalMsg
Definition qlogging.h:34
@ QtFatalMsg
Definition qlogging.h:35
@ QtDebugMsg
Definition qlogging.h:31
Q_CORE_EXPORT void qt_message_output(QtMsgType, const QMessageLogContext &context, const QString &message)
void(* QtMessageHandler)(QtMsgType, const QMessageLogContext &, const QString &)
Definition qlogging.h:197
#define Q_LOGGING_CATEGORY(name,...)
#define QT_MESSAGE_LOGGER_COMMON(category, level)
#define Q_DECLARE_LOGGING_CATEGORY(name)
QMutex QBasicMutex
Definition qmutex.h:360
QScopeGuard(F(&)()) -> QScopeGuard< F(*)()>
qsizetype erase(QVarLengthArray< T, Prealloc > &array, const AT &t)
qsizetype erase_if(QVarLengthArray< T, Prealloc > &array, Predicate pred)
size_t qHash(const QVarLengthArray< T, Prealloc > &key, size_t seed=0) noexcept(QtPrivate::QNothrowHashable_v< T >)
void setPattern(const QString &pattern)
std::unique_ptr< std::unique_ptr< const char[]>[]> literals
std::chrono::steady_clock::time_point appStartTime
std::unique_ptr< const char *[]> tokens
QList< QString > timeArgs
static QBasicMutex mutex
void setDefaultPattern()
void operator()(void *p) const noexcept
static constexpr bool Value
Definition qdebug.h:679
static constexpr bool Value
Definition qdebug.h:675