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 otherInlineStorage = other.array;
399 if (other.ptr != otherInlineStorage) {
400 // heap storage: steal the external buffer, reset other to otherInlineStorage
401 this->a = std::exchange(other.a, Prealloc);
402 this->ptr = std::exchange(other.ptr, otherInlineStorage);
403 } else {
404 // inline storage: move into our storage (doesn't matter whether inline or external)
405 QtPrivate::q_uninitialized_relocate_n(other.data(), other.size(), data());
406 }
407 this->s = std::exchange(other.s, 0);
408 return *this;
409 }
410
411 QVarLengthArray<T, Prealloc> &operator=(std::initializer_list<T> list)
412 {
413 assign(list);
414 return *this;
415 }
416
417 inline void removeLast()
418 {
419 Base::pop_back();
420 }
421#ifdef Q_QDOC
422 inline qsizetype size() const { return this->s; }
423 static constexpr qsizetype maxSize() noexcept { return QVLABase<T>::maxSize(); }
424 constexpr qsizetype max_size() const noexcept { return QVLABase<T>::max_size(); }
425#endif
426 using Base::size;
427 using Base::max_size;
428 inline qsizetype count() const { return size(); }
429 inline qsizetype length() const { return size(); }
430 inline T &first()
431 {
432 return front();
433 }
434 inline const T &first() const
435 {
436 return front();
437 }
438 T &last()
439 {
440 return back();
441 }
442 const T &last() const
443 {
444 return back();
445 }
446 bool isEmpty() const { return empty(); }
447 void resize(qsizetype sz) { Base::resize_impl(Prealloc, this->array, sz); }
448#ifndef Q_QDOC
449 template <typename U = T, if_copyable<U> = true>
450#endif
451 void resize(qsizetype sz, const T &v)
452 { Base::resize_impl(Prealloc, this->array, sz, v); }
453 using Base::clear;
454#ifdef Q_QDOC
455 inline void clear() { resize(0); }
456#endif
457 void squeeze() { reallocate(size(), size()); }
458
459 using Base::capacity;
460#ifdef Q_QDOC
461 qsizetype capacity() const { return this->a; }
462#endif
463 void reserve(qsizetype sz) { if (sz > capacity()) reallocate(size(), sz); }
464
465#ifdef Q_QDOC
466 template <typename AT = T>
467 inline qsizetype indexOf(const AT &t, qsizetype from = 0) const;
468 template <typename AT = T>
469 inline qsizetype lastIndexOf(const AT &t, qsizetype from = -1) const;
470 template <typename AT = T>
471 inline bool contains(const AT &t) const;
472#endif
473 using Base::indexOf;
474 using Base::lastIndexOf;
475 using Base::contains;
476
477#ifdef Q_QDOC
478 inline T &operator[](qsizetype idx)
479 {
480 verify(idx);
481 return data()[idx];
482 }
483 inline const T &operator[](qsizetype idx) const
484 {
485 verify(idx);
486 return data()[idx];
487 }
488#endif
489 using Base::operator[];
490 inline const T &at(qsizetype idx) const { return operator[](idx); }
491
492#ifdef Q_QDOC
493 T value(qsizetype i) const;
494 T value(qsizetype i, const T &defaultValue) const;
495#endif
496 using Base::value;
497
498 inline void append(const T &t)
499 {
500 if (size() == capacity())
501 emplace_back(T(t));
502 else
503 emplace_back(t);
504 }
505
506 void append(T &&t)
507 {
508 emplace_back(std::move(t));
509 }
510
511 void append(const T *buf, qsizetype sz)
512 { Base::append_impl(Prealloc, this->array, buf, sz); }
513 inline QVarLengthArray<T, Prealloc> &operator<<(const T &t)
514 { append(t); return *this; }
515 inline QVarLengthArray<T, Prealloc> &operator<<(T &&t)
516 { append(std::move(t)); return *this; }
517 inline QVarLengthArray<T, Prealloc> &operator+=(const T &t)
518 { append(t); return *this; }
519 inline QVarLengthArray<T, Prealloc> &operator+=(T &&t)
520 { append(std::move(t)); return *this; }
521
522#if QT_DEPRECATED_SINCE(6, 3)
523 QT_DEPRECATED_VERSION_X_6_3("This is slow. If you must, use insert(cbegin(), ~~~) instead.")
524 void prepend(T &&t);
525 QT_DEPRECATED_VERSION_X_6_3("This is slow. If you must, use insert(cbegin(), ~~~) instead.")
526 void prepend(const T &t);
527#endif
528 void insert(qsizetype i, T &&t);
529 void insert(qsizetype i, const T &t);
530 void insert(qsizetype i, qsizetype n, const T &t);
531
532 QVarLengthArray &assign(qsizetype n, const T &t)
533 { Base::assign_impl(Prealloc, this->array, n, t); return *this; }
534 template <typename InputIterator, if_input_iterator<InputIterator> = true>
535 QVarLengthArray &assign(InputIterator first, InputIterator last)
536 { Base::assign_impl(Prealloc, this->array, first, last); return *this; }
537 QVarLengthArray &assign(std::initializer_list<T> list)
538 { assign(list.begin(), list.end()); return *this; }
539
540#ifdef Q_QDOC
541 void replace(qsizetype i, const T &t);
542 void remove(qsizetype i, qsizetype n = 1);
543 void removeAt(qsizetype i);
544 template <typename AT = T>
545 qsizetype removeAll(const AT &t);
546 template <typename AT = T>
547 bool removeOne(const AT &t);
548 template <typename Predicate>
550#endif
551 using Base::replace;
552 using Base::remove;
553 using Base::removeAt;
554 using Base::removeAll;
555 using Base::removeOne;
556 using Base::removeIf;
557
558#ifdef Q_QDOC
559 inline T *data() { return this->ptr; }
560 inline const T *data() const { return this->ptr; }
561#endif
562 using Base::data;
563 inline const T *constData() const { return data(); }
564#ifdef Q_QDOC
565 inline iterator begin() { return data(); }
566 inline const_iterator begin() const { return data(); }
567 inline const_iterator cbegin() const { return begin(); }
568 inline const_iterator constBegin() const { return begin(); }
569 inline iterator end() { return data() + size(); }
570 inline const_iterator end() const { return data() + size(); }
571 inline const_iterator cend() const { return end(); }
572#endif
573
574 using Base::begin;
575 using Base::cbegin;
576 auto constBegin() const -> const_iterator { return begin(); }
577 using Base::end;
578 using Base::cend;
579 inline const_iterator constEnd() const { return end(); }
580#ifdef Q_QDOC
587#endif
588 using Base::rbegin;
589 using Base::crbegin;
590 using Base::rend;
591 using Base::crend;
592
593 iterator insert(const_iterator before, qsizetype n, const T &x)
594 { return Base::insert_impl(Prealloc, this->array, before, n, x); }
595 iterator insert(const_iterator before, T &&x) { return emplace(before, std::move(x)); }
596 inline iterator insert(const_iterator before, const T &x) { return insert(before, 1, x); }
597#ifdef Q_QDOC
599 inline iterator erase(const_iterator pos) { return erase(pos, pos + 1); }
600#endif
601 using Base::erase;
602
603 // STL compatibility:
604#ifdef Q_QDOC
605 inline bool empty() const { return isEmpty(); }
606#endif
607 using Base::empty;
608 inline void push_back(const T &t) { append(t); }
609 void push_back(T &&t) { append(std::move(t)); }
610#ifdef Q_QDOC
611 inline void pop_back() { removeLast(); }
612 inline T &front() { return first(); }
613 inline const T &front() const { return first(); }
614 inline T &back() { return last(); }
615 inline const T &back() const { return last(); }
616#endif
617 using Base::pop_back;
618 using Base::front;
619 using Base::back;
621 template <typename...Args>
622 iterator emplace(const_iterator pos, Args &&...args)
623 { return Base::emplace_impl(Prealloc, this->array, pos, std::forward<Args>(args)...); }
624 template <typename...Args>
625 T &emplace_back(Args &&...args)
626 { return Base::emplace_back_impl(Prealloc, this->array, std::forward<Args>(args)...); }
627
628
629#ifdef Q_QDOC
630 template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
631 friend inline bool operator==(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r);
632 template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
633 friend inline bool operator!=(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r);
634 template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
635 friend inline bool operator< (const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r);
636 template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
637 friend inline bool operator> (const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r);
638 template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
639 friend inline bool operator<=(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r);
640 template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
641 friend inline bool operator>=(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r);
642 template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
643 friend inline auto operator<=>(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r);
644#else
645private:
646 template <typename U = T, qsizetype Prealloc2 = Prealloc,
647 Qt::if_has_qt_compare_three_way<U, U> = true>
648 friend auto
649 compareThreeWay(const QVarLengthArray &lhs, const QVarLengthArray<T, Prealloc2> &rhs)
650 {
651 return QtOrderingPrivate::lexicographicalCompareThreeWay(lhs.begin(), lhs.end(),
652 rhs.begin(), rhs.end());
653 }
654
655#if defined(__cpp_lib_three_way_comparison) && defined(__cpp_lib_concepts)
656 template <typename U = T, qsizetype Prealloc2 = Prealloc,
658 friend auto
660 {
662 rhs.begin(), rhs.end(),
664 }
665#endif // __cpp_lib_three_way_comparison && __cpp_lib_concepts
666
667public:
668 template <typename U = T, qsizetype Prealloc2 = Prealloc> friend
669 QTypeTraits::compare_eq_result<U> operator==(const QVarLengthArray<T, Prealloc> &l, const QVarLengthArray<T, Prealloc2> &r)
670 {
671 return l.equal(r);
672 }
673
674 template <typename U = T, qsizetype Prealloc2 = Prealloc> friend
675 QTypeTraits::compare_eq_result<U> operator!=(const QVarLengthArray<T, Prealloc> &l, const QVarLengthArray<T, Prealloc2> &r)
676 {
677 return !(l == r);
678 }
679
680#ifndef __cpp_lib_three_way_comparison
681 template <typename U = T, qsizetype Prealloc2 = Prealloc> friend
682 QTypeTraits::compare_lt_result<U> operator<(const QVarLengthArray<T, Prealloc> &lhs, const QVarLengthArray<T, Prealloc2> &rhs)
683 noexcept(noexcept(std::lexicographical_compare(lhs.begin(), lhs.end(),
684 rhs.begin(), rhs.end())))
685 {
686 return lhs.less_than(rhs);
687 }
688
689 template <typename U = T, qsizetype Prealloc2 = Prealloc> friend
690 QTypeTraits::compare_lt_result<U> operator>(const QVarLengthArray<T, Prealloc> &lhs, const QVarLengthArray<T, Prealloc2> &rhs)
691 noexcept(noexcept(lhs < rhs))
692 {
693 return rhs < lhs;
694 }
695
696 template <typename U = T, qsizetype Prealloc2 = Prealloc> friend
697 QTypeTraits::compare_lt_result<U> operator<=(const QVarLengthArray<T, Prealloc> &lhs, const QVarLengthArray<T, Prealloc2> &rhs)
698 noexcept(noexcept(lhs < rhs))
699 {
700 return !(lhs > rhs);
701 }
702
703 template <typename U = T, qsizetype Prealloc2 = Prealloc> friend
704 QTypeTraits::compare_lt_result<U> operator>=(const QVarLengthArray<T, Prealloc> &lhs, const QVarLengthArray<T, Prealloc2> &rhs)
705 noexcept(noexcept(lhs < rhs))
706 {
707 return !(lhs < rhs);
708 }
709#endif // __cpp_lib_three_way_comparison
710#endif // Q_QDOC
711
712private:
713 template <typename U, qsizetype Prealloc2>
714 bool equal(const QVarLengthArray<U, Prealloc2> &other) const
715 { return Base::equal(other); }
716 template <typename U, qsizetype Prealloc2>
717 bool less_than(const QVarLengthArray<U, Prealloc2> &other) const
718 { return Base::less_than(other); }
719
720 void reallocate(qsizetype sz, qsizetype alloc)
721 { Base::reallocate_impl(Prealloc, this->array, sz, alloc); }
722
723 using Base::isValidIterator;
724};
725
726template <typename InputIterator,
727 typename ValueType = typename std::iterator_traits<InputIterator>::value_type,
728 QtPrivate::IfIsInputIterator<InputIterator> = true>
729QVarLengthArray(InputIterator, InputIterator) -> QVarLengthArray<ValueType>;
730
731template <class T, qsizetype Prealloc>
732Q_INLINE_TEMPLATE QVarLengthArray<T, Prealloc>::QVarLengthArray(qsizetype asize)
733 : QVarLengthArray()
734{
735 Q_ASSERT_X(asize >= 0, "QVarLengthArray::QVarLengthArray(qsizetype)",
736 "Size must be greater than or equal to 0.");
737
738 // historically, this ctor worked for non-copyable/non-movable T, so keep it working, why not?
739 // resize(asize) // this requires a movable or copyable T, can't use, need to do it by hand
740
741 if (asize > Prealloc) {
742 this->a = asize;
743 this->ptr = QtPrivate::fittedMalloc(0, &this->a, sizeof(T));
744 Q_CHECK_PTR(this->ptr);
745 }
746 if constexpr (QTypeInfo<T>::isComplex)
747 std::uninitialized_default_construct_n(data(), asize);
748 this->s = asize;
749}
750
751template <class T>
752template <typename AT>
753Q_INLINE_TEMPLATE qsizetype QVLABase<T>::indexOf(const AT &t, qsizetype from) const
754{
755 if (from < 0)
756 from = qMax(from + size(), qsizetype(0));
757 if (from < size()) {
758 const T *n = data() + from - 1;
759 const T *e = end();
760 while (++n != e)
761 if (*n == t)
762 return n - data();
763 }
764 return -1;
765}
766
767template <class T>
768template <typename AT>
769Q_INLINE_TEMPLATE qsizetype QVLABase<T>::lastIndexOf(const AT &t, qsizetype from) const
770{
771 if (from < 0)
772 from += size();
773 else if (from >= size())
774 from = size() - 1;
775 if (from >= 0) {
776 const T *b = begin();
777 const T *n = b + from + 1;
778 while (n != b) {
779 if (*--n == t)
780 return n - b;
781 }
782 }
783 return -1;
784}
785
786template <class T>
787template <typename AT>
788Q_INLINE_TEMPLATE bool QVLABase<T>::contains(const AT &t) const
789{
790 const T *b = begin();
791 const T *i = end();
792 while (i != b) {
793 if (*--i == t)
794 return true;
795 }
796 return false;
797}
798
799template <class T>
800Q_OUTOFLINE_TEMPLATE void QVLABase<T>::append_impl(qsizetype prealloc, void *array, const T *abuf, qsizetype increment)
801{
802 Q_ASSERT(abuf || increment == 0);
803 if (increment <= 0)
804 return;
805
806 const qsizetype asize = size() + increment;
807
808 if (asize >= capacity())
809 growBy(prealloc, array, increment);
810
811 if constexpr (QTypeInfo<T>::isComplex)
812 std::uninitialized_copy_n(abuf, increment, end());
813 else
814 memcpy(static_cast<void *>(end()), static_cast<const void *>(abuf), increment * sizeof(T));
815
816 this->s = asize;
817}
818
819template <class T>
820Q_OUTOFLINE_TEMPLATE void QVLABase<T>::assign_impl(qsizetype prealloc, void *array, qsizetype n, const T &t)
821{
822 Q_ASSERT(n >= 0);
823 if (n > capacity()) {
824 reallocate_impl(prealloc, array, 0, capacity()); // clear
825 resize_impl(prealloc, array, n, t);
826 } else {
827 auto mid = (std::min)(n, size());
828 std::fill(data(), data() + mid, t);
829 std::uninitialized_fill(data() + mid, data() + n, t);
830 s = n;
831 erase(data() + n, data() + size());
832 }
833}
834
835template <class T>
836template <typename Iterator>
838void QVLABase<T>::assign_impl(qsizetype prealloc, void *array, Iterator first, Iterator last,
839 std::forward_iterator_tag)
840{
841 // This function only provides the basic exception guarantee.
842 const qsizetype n = std::distance(first, last);
843 if (n > capacity())
844 reallocate_impl(prealloc, array, 0, n); // clear & reserve n
845
846 auto dst = begin();
847
848 if constexpr (!QTypeInfo<T>::isComplex) {
849 // For non-complex types, we prefer a single std::copy() -> memcpy()
850 // call. We can do that because either the default constructor is
851 // trivial (so the lifetime has started) or the copy constructor is
852 // (and won't care what the stored value is). Note that in some cases
853 // dst > end() after this.
854 dst = std::copy(first, last, dst);
855 } else if (n > this->s) {
856 // overwrite existing elements and create new
857 for (qsizetype i = 0; i < this->s; ++i) {
858 *dst = *first;
859 ++first;
860 ++dst;
861 }
862 std::uninitialized_copy_n(first, n - this->s, dst);
863 } else {
864 // overwrite existing elements and destroy tail
865 dst = std::copy(first, last, dst);
866 std::destroy(dst, end());
867 }
868 this->s = n;
869}
870
871template <class T>
872template <typename Iterator>
874void QVLABase<T>::assign_impl(qsizetype prealloc, void *array, Iterator first, Iterator last,
875 std::input_iterator_tag)
876{
877 // This function only provides the basic exception guarantee.
878 auto dst = begin();
879 const auto dend = end();
880 while (true) {
881 if (first == last) { // ran out of elements to assign
882 std::destroy(dst, dend);
883 break;
884 }
885 if (dst == dend) { // ran out of existing elements to overwrite
886 do {
887 emplace_back_impl(prealloc, array, *first);
888 } while (++first != last);
889 return; // size() is already correct (and dst invalidated)!
890 }
891 *dst = *first; // overwrite existing element
892 ++dst;
893 ++first;
894 }
895 this->s = dst - begin();
896}
897
898template <class T>
899template <typename Iterator>
901void QVLABase<T>::assign_impl(qsizetype prealloc, void *array, Iterator first, Iterator last)
902{
903 using Cat = typename std::iterator_traits<Iterator>::iterator_category;
904 assign_impl(prealloc, array, first, last, Cat{});
905}
906
907template <class T>
908Q_OUTOFLINE_TEMPLATE void QVLABase<T>::reallocate_impl(qsizetype prealloc, void *array, qsizetype asize, qsizetype aalloc)
909{
910 Q_ASSERT(aalloc >= asize);
911 Q_ASSERT(data());
912 T *oldPtr = data();
913 qsizetype osize = size();
914 const qsizetype oalloc = capacity();
915
916 const qsizetype copySize = qMin(asize, osize);
917 Q_ASSERT(copySize >= 0);
918
919 if (aalloc != oalloc) {
921 void *newPtr;
922 qsizetype newA;
923 if (aalloc > prealloc) {
924 newPtr = QtPrivate::fittedMalloc(0, &aalloc, sizeof(T));
925 guard.reset(newPtr);
926 Q_CHECK_PTR(newPtr); // could throw
927 // by design: in case of QT_NO_EXCEPTIONS malloc must not fail or it crashes here
928 newA = aalloc;
929 } else {
930 newPtr = array;
931 newA = prealloc;
932 }
933 QtPrivate::q_uninitialized_relocate_n(oldPtr, copySize,
934 reinterpret_cast<T *>(newPtr));
935 // commit:
936 ptr = newPtr;
937 guard.release();
938 a = newA;
939 }
940 s = copySize;
941
942 // destroy remaining old objects
943 if constexpr (QTypeInfo<T>::isComplex) {
944 if (osize > asize)
945 std::destroy(oldPtr + asize, oldPtr + osize);
946 }
947
948 if (oldPtr != reinterpret_cast<T *>(array) && oldPtr != data())
949 QtPrivate::sizedFree(oldPtr, oalloc, sizeof(T));
950}
951
952template <class T>
953Q_OUTOFLINE_TEMPLATE T QVLABase<T>::value(qsizetype i) const
954{
955 if (size_t(i) >= size_t(size()))
956 return T();
957 return operator[](i);
958}
959template <class T>
960Q_OUTOFLINE_TEMPLATE T QVLABase<T>::value(qsizetype i, const T &defaultValue) const
961{
962 return (size_t(i) >= size_t(size())) ? defaultValue : operator[](i);
963}
964
965template <class T, qsizetype Prealloc>
966inline void QVarLengthArray<T, Prealloc>::insert(qsizetype i, T &&t)
967{ verify(i, 0);
968 insert(cbegin() + i, std::move(t)); }
969template <class T, qsizetype Prealloc>
970inline void QVarLengthArray<T, Prealloc>::insert(qsizetype i, const T &t)
971{ verify(i, 0);
972 insert(begin() + i, 1, t); }
973template <class T, qsizetype Prealloc>
974inline void QVarLengthArray<T, Prealloc>::insert(qsizetype i, qsizetype n, const T &t)
975{ verify(i, 0);
976 insert(begin() + i, n, t); }
977template <class T>
978inline void QVLABase<T>::remove(qsizetype i, qsizetype n)
979{ verify(i, n);
980 erase(begin() + i, begin() + i + n); }
981template <class T>
982template <typename AT>
983inline qsizetype QVLABase<T>::removeAll(const AT &t)
984{ return QtPrivate::sequential_erase_with_copy(*this, t); }
985template <class T>
986template <typename AT>
987inline bool QVLABase<T>::removeOne(const AT &t)
988{ return QtPrivate::sequential_erase_one(*this, t); }
989template <class T>
990template <typename Predicate>
991inline qsizetype QVLABase<T>::removeIf(Predicate pred)
992{ return QtPrivate::sequential_erase_if(*this, pred); }
993#if QT_DEPRECATED_SINCE(6, 3)
994template <class T, qsizetype Prealloc>
995inline void QVarLengthArray<T, Prealloc>::prepend(T &&t)
996{ insert(cbegin(), std::move(t)); }
997template <class T, qsizetype Prealloc>
998inline void QVarLengthArray<T, Prealloc>::prepend(const T &t)
999{ insert(begin(), 1, t); }
1000#endif
1001
1002template <class T>
1003inline void QVLABase<T>::replace(qsizetype i, const T &t)
1004{
1005 verify(i);
1006 data()[i] = t;
1007}
1008
1009template <class T>
1010template <typename...Args>
1011Q_OUTOFLINE_TEMPLATE auto QVLABase<T>::emplace_impl(qsizetype prealloc, void *array, const_iterator before, Args &&...args) -> iterator
1012{
1013 Q_ASSERT_X(isValidIterator(before), "QVarLengthArray::insert", "The specified const_iterator argument 'before' is invalid");
1014 Q_ASSERT(size() <= capacity());
1015 Q_ASSERT(capacity() > 0);
1016
1017 const qsizetype offset = qsizetype(before - cbegin());
1018 emplace_back_impl(prealloc, array, std::forward<Args>(args)...);
1019 const auto b = begin() + offset;
1020 const auto e = end();
1021 QtPrivate::q_rotate(b, e - 1, e);
1022 return b;
1023}
1024
1025template <class T>
1026Q_OUTOFLINE_TEMPLATE auto QVLABase<T>::insert_impl(qsizetype prealloc, void *array, const_iterator before, qsizetype n, const T &t) -> iterator
1027{
1028 Q_ASSERT_X(isValidIterator(before), "QVarLengthArray::insert", "The specified const_iterator argument 'before' is invalid");
1029
1030 const qsizetype offset = qsizetype(before - cbegin());
1031 resize_impl(prealloc, array, size() + n, t);
1032 const auto b = begin() + offset;
1033 const auto e = end();
1034 QtPrivate::q_rotate(b, e - n, e);
1035 return b;
1036}
1037
1038template <class T>
1040{
1041 Q_ASSERT_X(isValidIterator(abegin), "QVarLengthArray::erase", "The specified const_iterator argument 'abegin' is invalid");
1042 Q_ASSERT_X(isValidIterator(aend), "QVarLengthArray::erase", "The specified const_iterator argument 'aend' is invalid");
1043
1044 qsizetype f = qsizetype(abegin - cbegin());
1045 qsizetype l = qsizetype(aend - cbegin());
1046 qsizetype n = l - f;
1047
1048 if (n == 0) // avoid UB in std::move() below
1049 return data() + f;
1050
1051 Q_ASSERT(n > 0); // aend must be reachable from abegin
1052
1053 if constexpr (!QTypeInfo<T>::isRelocatable) {
1054 std::move(begin() + l, end(), QT_MAKE_CHECKED_ARRAY_ITERATOR(begin() + f, size() - f));
1055 std::destroy(end() - n, end());
1056 } else {
1057 std::destroy(abegin, aend);
1058 memmove(static_cast<void *>(data() + f), static_cast<const void *>(data() + l), (size() - l) * sizeof(T));
1059 }
1060 this->s -= n;
1061 return data() + f;
1062}
1063
1064#ifdef Q_QDOC
1065// Fake definitions for qdoc, only the redeclaration is used.
1066template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
1067bool operator==(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r)
1068{ return bool{}; }
1069template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
1070bool operator!=(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r)
1071{ return bool{}; }
1072template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
1073bool operator< (const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r)
1074{ return bool{}; }
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{}; }
1084#endif
1085
1086template <typename T, qsizetype Prealloc>
1087size_t qHash(const QVarLengthArray<T, Prealloc> &key, size_t seed = 0)
1088 noexcept(QtPrivate::QNothrowHashable_v<T>)
1089{
1090 return key.hash(seed);
1091}
1092
1093template <typename T, qsizetype Prealloc, typename AT>
1094qsizetype erase(QVarLengthArray<T, Prealloc> &array, const AT &t)
1095{
1096 return array.removeAll(t);
1097}
1098
1099template <typename T, qsizetype Prealloc, typename Predicate>
1100qsizetype erase_if(QVarLengthArray<T, Prealloc> &array, Predicate pred)
1101{
1102 return array.removeIf(pred);
1103}
1104
1105QT_END_NAMESPACE
1106
1107#endif // QVARLENGTHARRAY_H
QByteArray & operator*() noexcept
Definition qbytearray.h:803
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:807
void swap(QByteArray::FromBase64Result &other) noexcept
Definition qbytearray.h:790
operator bool() const noexcept
\variable QByteArray::FromBase64Result::decoded
Definition qbytearray.h:796
const QByteArray & operator*() const noexcept
Returns the decoded byte array.
Definition qbytearray.h:804
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:818
\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:853
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:836
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:830
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