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 template <typename AT = T>
177 qsizetype removeAll(const AT &t);
178 template <typename AT = T>
179 bool removeOne(const AT &t);
180 template <typename Predicate>
181 qsizetype removeIf(Predicate pred);
182
183 void clear()
184 {
185 if constexpr (QTypeInfo<T>::isComplex)
186 std::destroy_n(data(), size());
187 s = 0;
188 }
189
191 iterator erase(const_iterator pos) { return erase(pos, pos + 1); }
192
193 static constexpr qsizetype maxSize() noexcept
194 {
195 // -1 to deal with the pointer one-past-the-end
196 return (QtPrivate::MaxAllocSize / sizeof(T)) - 1;
197 }
198 constexpr qsizetype max_size() const noexcept
199 {
200 return maxSize();
201 }
202
203 size_t hash(size_t seed) const noexcept(QtPrivate::QNothrowHashable_v<T>)
204 {
205 return qHashRange(begin(), end(), seed);
206 }
207protected:
208 void growBy(qsizetype prealloc, void *array, qsizetype increment)
209 { reallocate_impl(prealloc, array, size(), (std::max)(size() * 2, size() + increment)); }
210 template <typename...Args>
211 reference emplace_back_impl(qsizetype prealloc, void *array, Args&&...args)
212 {
213 if (size() == capacity()) // ie. size() != 0
214 growBy(prealloc, array, 1);
215 reference r = *q20::construct_at(end(), std::forward<Args>(args)...);
216 ++s;
217 return r;
218 }
219 template <typename...Args>
220 iterator emplace_impl(qsizetype prealloc, void *array, const_iterator pos, Args&&...arg);
221
222 iterator insert_impl(qsizetype prealloc, void *array, const_iterator pos, qsizetype n, const T &t);
223
224 template <typename S>
225 bool equal(const QVLABase<S> &other) const
226 {
227 return std::equal(begin(), end(), other.begin(), other.end());
228 }
229 template <typename S>
230 bool less_than(const QVLABase<S> &other) const
231 {
232 return std::lexicographical_compare(begin(), end(), other.begin(), other.end());
233 }
234
235 void append_impl(qsizetype prealloc, void *array, const T *buf, qsizetype n);
236 void reallocate_impl(qsizetype prealloc, void *array, qsizetype size, qsizetype alloc);
237 void resize_impl(qsizetype prealloc, void *array, qsizetype sz, const T &v)
238 {
239 if (QtPrivate::q_points_into_range(&v, begin(), end())) {
240 resize_impl(prealloc, array, sz, T(v));
241 return;
242 }
243 reallocate_impl(prealloc, array, sz, qMax(sz, capacity()));
244 while (size() < sz) {
245 q20::construct_at(data() + size(), v);
246 ++s;
247 }
248 }
249 void resize_impl(qsizetype prealloc, void *array, qsizetype sz)
250 {
251 reallocate_impl(prealloc, array, sz, qMax(sz, capacity()));
252 if constexpr (QTypeInfo<T>::isComplex) {
253 // call default constructor for new objects (which can throw)
254 while (size() < sz) {
255 q20::construct_at(data() + size());
256 ++s;
257 }
258 } else {
259 s = sz;
260 }
261 }
262
263 void assign_impl(qsizetype prealloc, void *array, qsizetype n, const T &t);
264 template <typename Iterator>
265 void assign_impl(qsizetype prealloc, void *array, Iterator first, Iterator last,
266 std::forward_iterator_tag);
267 template <typename Iterator>
268 void assign_impl(qsizetype prealloc, void *array, Iterator first, Iterator last,
269 std::input_iterator_tag);
270 template <typename Iterator>
271 void assign_impl(qsizetype prealloc, void *array, Iterator first, Iterator last);
272
273 bool isValidIterator(const const_iterator &i) const
274 {
275 const std::less<const T *> less = {};
276 return !less(cend(), i) && !less(i, cbegin());
277 }
278};
279
280// Prealloc = 256 by default, specified in qcontainerfwd.h
281template<class T, qsizetype Prealloc>
283#if QT_VERSION >= QT_VERSION_CHECK(7,0,0) || defined(QT_BOOTSTRAPPED)
284 : public QVLAStorage<sizeof(T), alignof(T), Prealloc>,
285 public QVLABase<T>
286#else
287 : public QVLABase<T>,
288 public QVLAStorage<sizeof(T), alignof(T), Prealloc>
289#endif
290{
291 template <class S, qsizetype Prealloc2>
292 friend class QVarLengthArray;
293 using Base = QVLABase<T>;
294 using Storage = QVLAStorage<sizeof(T), alignof(T), Prealloc>;
295 static_assert(Prealloc > 0, "QVarLengthArray Prealloc must be greater than 0.");
296 static_assert(std::is_nothrow_destructible_v<T>, "Types with throwing destructors are not supported in Qt containers.");
297 using Base::verify;
298
299 template <typename U>
301 template <typename InputIterator>
303public:
304 static constexpr qsizetype PreallocatedSize = Prealloc;
305
306 using size_type = typename Base::size_type;
307 using value_type = typename Base::value_type;
308 using pointer = typename Base::pointer;
309 using const_pointer = typename Base::const_pointer;
310 using reference = typename Base::reference;
311 using const_reference = typename Base::const_reference;
312 using difference_type = typename Base::difference_type;
313
314 using iterator = typename Base::iterator;
315 using const_iterator = typename Base::const_iterator;
316 using reverse_iterator = typename Base::reverse_iterator;
318
320 {
321 this->a = Prealloc;
322 this->s = 0;
323 this->ptr = this->array;
324 }
325
326 inline explicit QVarLengthArray(qsizetype size);
327
328#ifndef Q_QDOC
329 template <typename U = T, if_copyable<U> = true>
330#endif
331 explicit QVarLengthArray(qsizetype sz, const T &v)
333 {
334 resize(sz, v);
335 }
336
339 {
340 append(other.constData(), other.size());
341 }
342
345 : Base(other)
346 {
347 const auto otherInlineStorage = reinterpret_cast<T*>(other.array);
348 if (data() == otherInlineStorage) {
349 // inline buffer - move into our inline buffer:
350 this->ptr = this->array;
351 QtPrivate::q_uninitialized_relocate_n(otherInlineStorage, size(), data());
352 } else {
353 // heap buffer - we just stole the memory
354 }
355 // reset other to internal storage:
356 other.a = Prealloc;
357 other.s = 0;
358 other.ptr = otherInlineStorage;
359 }
360
361 QVarLengthArray(std::initializer_list<T> args)
362 : QVarLengthArray(args.begin(), args.end())
363 {
364 }
365
366 template <typename InputIterator, if_input_iterator<InputIterator> = true>
367 inline QVarLengthArray(InputIterator first, InputIterator last)
369 {
370 assign(first, last);
371 }
372
374 {
375 if constexpr (QTypeInfo<T>::isComplex)
376 std::destroy_n(data(), size());
377 if (data() != reinterpret_cast<T *>(this->array))
378 QtPrivate::sizedFree(data(), capacity(), sizeof(T));
379 }
380 inline QVarLengthArray<T, Prealloc> &operator=(const QVarLengthArray<T, Prealloc> &other)
381 {
382 if (this != &other) {
383 clear();
384 append(other.constData(), other.size());
385 }
386 return *this;
387 }
388
391 {
392 // we're only required to be self-move-assignment-safe
393 // when we're in the moved-from state (Hinnant criterion)
394 // the moved-from state is the empty state, so we're good with the clear() here:
395 clear();
396 Q_ASSERT(capacity() >= Prealloc);
397 const auto otherInlineStorage = other.array;
398 if (other.ptr != otherInlineStorage) {
399 // heap storage: steal the external buffer, reset other to otherInlineStorage
400 this->a = std::exchange(other.a, Prealloc);
401 this->ptr = std::exchange(other.ptr, otherInlineStorage);
402 } else {
403 // inline storage: move into our storage (doesn't matter whether inline or external)
404 QtPrivate::q_uninitialized_relocate_n(other.data(), other.size(), data());
405 }
406 this->s = std::exchange(other.s, 0);
407 return *this;
408 }
409
410 QVarLengthArray<T, Prealloc> &operator=(std::initializer_list<T> list)
411 {
412 assign(list);
413 return *this;
414 }
415
416 inline void removeLast()
417 {
418 Base::pop_back();
419 }
420#ifdef Q_QDOC
421 inline qsizetype size() const { return this->s; }
422 static constexpr qsizetype maxSize() noexcept { return QVLABase<T>::maxSize(); }
423 constexpr qsizetype max_size() const noexcept { return QVLABase<T>::max_size(); }
424#endif
425 using Base::size;
426 using Base::max_size;
427 inline qsizetype count() const { return size(); }
428 inline qsizetype length() const { return size(); }
429 inline T &first()
430 {
431 return front();
432 }
433 inline const T &first() const
434 {
435 return front();
436 }
437 T &last()
438 {
439 return back();
440 }
441 const T &last() const
442 {
443 return back();
444 }
445 bool isEmpty() const { return empty(); }
446 void resize(qsizetype sz) { Base::resize_impl(Prealloc, this->array, sz); }
447#ifndef Q_QDOC
448 template <typename U = T, if_copyable<U> = true>
449#endif
450 void resize(qsizetype sz, const T &v)
451 { Base::resize_impl(Prealloc, this->array, sz, v); }
452 using Base::clear;
453#ifdef Q_QDOC
454 inline void clear() { resize(0); }
455#endif
456 void squeeze() { reallocate(size(), size()); }
457
458 using Base::capacity;
459#ifdef Q_QDOC
460 qsizetype capacity() const { return this->a; }
461#endif
462 void reserve(qsizetype sz) { if (sz > capacity()) reallocate(size(), sz); }
463
464#ifdef Q_QDOC
465 template <typename AT = T>
466 inline qsizetype indexOf(const AT &t, qsizetype from = 0) const;
467 template <typename AT = T>
468 inline qsizetype lastIndexOf(const AT &t, qsizetype from = -1) const;
469 template <typename AT = T>
470 inline bool contains(const AT &t) const;
471#endif
472 using Base::indexOf;
473 using Base::lastIndexOf;
474 using Base::contains;
475
476#ifdef Q_QDOC
477 inline T &operator[](qsizetype idx)
478 {
479 verify(idx);
480 return data()[idx];
481 }
482 inline const T &operator[](qsizetype idx) const
483 {
484 verify(idx);
485 return data()[idx];
486 }
487#endif
488 using Base::operator[];
489 inline const T &at(qsizetype idx) const { return operator[](idx); }
490
491#ifdef Q_QDOC
492 T value(qsizetype i) const;
493 T value(qsizetype i, const T &defaultValue) const;
494#endif
495 using Base::value;
496
497 inline void append(const T &t)
498 {
499 if (size() == capacity())
500 emplace_back(T(t));
501 else
502 emplace_back(t);
503 }
504
505 void append(T &&t)
506 {
507 emplace_back(std::move(t));
508 }
509
510 void append(const T *buf, qsizetype sz)
511 { Base::append_impl(Prealloc, this->array, buf, sz); }
512 inline QVarLengthArray<T, Prealloc> &operator<<(const T &t)
513 { append(t); return *this; }
514 inline QVarLengthArray<T, Prealloc> &operator<<(T &&t)
515 { append(std::move(t)); return *this; }
516 inline QVarLengthArray<T, Prealloc> &operator+=(const T &t)
517 { append(t); return *this; }
518 inline QVarLengthArray<T, Prealloc> &operator+=(T &&t)
519 { append(std::move(t)); return *this; }
520
521#if QT_DEPRECATED_SINCE(6, 3)
522 QT_DEPRECATED_VERSION_X_6_3("This is slow. If you must, use insert(cbegin(), ~~~) instead.")
523 void prepend(T &&t);
524 QT_DEPRECATED_VERSION_X_6_3("This is slow. If you must, use insert(cbegin(), ~~~) instead.")
525 void prepend(const T &t);
526#endif
527 void insert(qsizetype i, T &&t);
528 void insert(qsizetype i, const T &t);
529 void insert(qsizetype i, qsizetype n, const T &t);
530
531 QVarLengthArray &assign(qsizetype n, const T &t)
532 { Base::assign_impl(Prealloc, this->array, n, t); return *this; }
533 template <typename InputIterator, if_input_iterator<InputIterator> = true>
534 QVarLengthArray &assign(InputIterator first, InputIterator last)
535 { Base::assign_impl(Prealloc, this->array, first, last); return *this; }
536 QVarLengthArray &assign(std::initializer_list<T> list)
537 { assign(list.begin(), list.end()); return *this; }
538
539#ifdef Q_QDOC
540 void replace(qsizetype i, const T &t);
541 void remove(qsizetype i, qsizetype n = 1);
542 template <typename AT = T>
543 qsizetype removeAll(const AT &t);
544 template <typename AT = T>
545 bool removeOne(const AT &t);
546 template <typename Predicate>
548#endif
549 using Base::replace;
550 using Base::remove;
551 using Base::removeAll;
552 using Base::removeOne;
553 using Base::removeIf;
554
555#ifdef Q_QDOC
556 inline T *data() { return this->ptr; }
557 inline const T *data() const { return this->ptr; }
558#endif
559 using Base::data;
560 inline const T *constData() const { return data(); }
561#ifdef Q_QDOC
562 inline iterator begin() { return data(); }
563 inline const_iterator begin() const { return data(); }
564 inline const_iterator cbegin() const { return begin(); }
565 inline const_iterator constBegin() const { return begin(); }
566 inline iterator end() { return data() + size(); }
567 inline const_iterator end() const { return data() + size(); }
568 inline const_iterator cend() const { return end(); }
569#endif
570
571 using Base::begin;
572 using Base::cbegin;
573 auto constBegin() const -> const_iterator { return begin(); }
574 using Base::end;
575 using Base::cend;
576 inline const_iterator constEnd() const { return end(); }
577#ifdef Q_QDOC
584#endif
585 using Base::rbegin;
586 using Base::crbegin;
587 using Base::rend;
588 using Base::crend;
589
590 iterator insert(const_iterator before, qsizetype n, const T &x)
591 { return Base::insert_impl(Prealloc, this->array, before, n, x); }
592 iterator insert(const_iterator before, T &&x) { return emplace(before, std::move(x)); }
593 inline iterator insert(const_iterator before, const T &x) { return insert(before, 1, x); }
594#ifdef Q_QDOC
596 inline iterator erase(const_iterator pos) { return erase(pos, pos + 1); }
597#endif
598 using Base::erase;
599
600 // STL compatibility:
601#ifdef Q_QDOC
602 inline bool empty() const { return isEmpty(); }
603#endif
604 using Base::empty;
605 inline void push_back(const T &t) { append(t); }
606 void push_back(T &&t) { append(std::move(t)); }
607#ifdef Q_QDOC
608 inline void pop_back() { removeLast(); }
609 inline T &front() { return first(); }
610 inline const T &front() const { return first(); }
611 inline T &back() { return last(); }
612 inline const T &back() const { return last(); }
613#endif
614 using Base::pop_back;
615 using Base::front;
616 using Base::back;
618 template <typename...Args>
619 iterator emplace(const_iterator pos, Args &&...args)
620 { return Base::emplace_impl(Prealloc, this->array, pos, std::forward<Args>(args)...); }
621 template <typename...Args>
622 T &emplace_back(Args &&...args)
623 { return Base::emplace_back_impl(Prealloc, this->array, std::forward<Args>(args)...); }
624
625
626#ifdef Q_QDOC
627 template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
628 friend inline bool operator==(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r);
629 template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
630 friend inline bool operator!=(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r);
631 template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
632 friend inline bool operator< (const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r);
633 template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
634 friend inline bool operator> (const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r);
635 template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
636 friend inline bool operator<=(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r);
637 template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
638 friend inline bool operator>=(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r);
639 template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
640 friend inline auto operator<=>(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r);
641#else
642private:
643 template <typename U = T, qsizetype Prealloc2 = Prealloc,
644 Qt::if_has_qt_compare_three_way<U, U> = true>
645 friend auto
646 compareThreeWay(const QVarLengthArray &lhs, const QVarLengthArray<T, Prealloc2> &rhs)
647 {
648 return QtOrderingPrivate::lexicographicalCompareThreeWay(lhs.begin(), lhs.end(),
649 rhs.begin(), rhs.end());
650 }
651
652#if defined(__cpp_lib_three_way_comparison) && defined(__cpp_lib_concepts)
653 template <typename U = T, qsizetype Prealloc2 = Prealloc,
655 friend auto
657 {
659 rhs.begin(), rhs.end(),
661 }
662#endif // __cpp_lib_three_way_comparison && __cpp_lib_concepts
663
664public:
665 template <typename U = T, qsizetype Prealloc2 = Prealloc> friend
666 QTypeTraits::compare_eq_result<U> operator==(const QVarLengthArray<T, Prealloc> &l, const QVarLengthArray<T, Prealloc2> &r)
667 {
668 return l.equal(r);
669 }
670
671 template <typename U = T, qsizetype Prealloc2 = Prealloc> friend
672 QTypeTraits::compare_eq_result<U> operator!=(const QVarLengthArray<T, Prealloc> &l, const QVarLengthArray<T, Prealloc2> &r)
673 {
674 return !(l == r);
675 }
676
677#ifndef __cpp_lib_three_way_comparison
678 template <typename U = T, qsizetype Prealloc2 = Prealloc> friend
679 QTypeTraits::compare_lt_result<U> operator<(const QVarLengthArray<T, Prealloc> &lhs, const QVarLengthArray<T, Prealloc2> &rhs)
680 noexcept(noexcept(std::lexicographical_compare(lhs.begin(), lhs.end(),
681 rhs.begin(), rhs.end())))
682 {
683 return lhs.less_than(rhs);
684 }
685
686 template <typename U = T, qsizetype Prealloc2 = Prealloc> friend
687 QTypeTraits::compare_lt_result<U> operator>(const QVarLengthArray<T, Prealloc> &lhs, const QVarLengthArray<T, Prealloc2> &rhs)
688 noexcept(noexcept(lhs < rhs))
689 {
690 return rhs < lhs;
691 }
692
693 template <typename U = T, qsizetype Prealloc2 = Prealloc> friend
694 QTypeTraits::compare_lt_result<U> operator<=(const QVarLengthArray<T, Prealloc> &lhs, const QVarLengthArray<T, Prealloc2> &rhs)
695 noexcept(noexcept(lhs < rhs))
696 {
697 return !(lhs > rhs);
698 }
699
700 template <typename U = T, qsizetype Prealloc2 = Prealloc> friend
701 QTypeTraits::compare_lt_result<U> operator>=(const QVarLengthArray<T, Prealloc> &lhs, const QVarLengthArray<T, Prealloc2> &rhs)
702 noexcept(noexcept(lhs < rhs))
703 {
704 return !(lhs < rhs);
705 }
706#endif // __cpp_lib_three_way_comparison
707#endif // Q_QDOC
708
709private:
710 template <typename U, qsizetype Prealloc2>
711 bool equal(const QVarLengthArray<U, Prealloc2> &other) const
712 { return Base::equal(other); }
713 template <typename U, qsizetype Prealloc2>
714 bool less_than(const QVarLengthArray<U, Prealloc2> &other) const
715 { return Base::less_than(other); }
716
717 void reallocate(qsizetype sz, qsizetype alloc)
718 { Base::reallocate_impl(Prealloc, this->array, sz, alloc); }
719
720 using Base::isValidIterator;
721};
722
723template <typename InputIterator,
724 typename ValueType = typename std::iterator_traits<InputIterator>::value_type,
725 QtPrivate::IfIsInputIterator<InputIterator> = true>
726QVarLengthArray(InputIterator, InputIterator) -> QVarLengthArray<ValueType>;
727
728template <class T, qsizetype Prealloc>
729Q_INLINE_TEMPLATE QVarLengthArray<T, Prealloc>::QVarLengthArray(qsizetype asize)
730 : QVarLengthArray()
731{
732 Q_ASSERT_X(asize >= 0, "QVarLengthArray::QVarLengthArray(qsizetype)",
733 "Size must be greater than or equal to 0.");
734
735 // historically, this ctor worked for non-copyable/non-movable T, so keep it working, why not?
736 // resize(asize) // this requires a movable or copyable T, can't use, need to do it by hand
737
738 if (asize > Prealloc) {
739 this->a = asize;
740 this->ptr = QtPrivate::fittedMalloc(0, &this->a, sizeof(T));
741 Q_CHECK_PTR(this->ptr);
742 }
743 if constexpr (QTypeInfo<T>::isComplex)
744 std::uninitialized_default_construct_n(data(), asize);
745 this->s = asize;
746}
747
748template <class T>
749template <typename AT>
750Q_INLINE_TEMPLATE qsizetype QVLABase<T>::indexOf(const AT &t, qsizetype from) const
751{
752 if (from < 0)
753 from = qMax(from + size(), qsizetype(0));
754 if (from < size()) {
755 const T *n = data() + from - 1;
756 const T *e = end();
757 while (++n != e)
758 if (*n == t)
759 return n - data();
760 }
761 return -1;
762}
763
764template <class T>
765template <typename AT>
766Q_INLINE_TEMPLATE qsizetype QVLABase<T>::lastIndexOf(const AT &t, qsizetype from) const
767{
768 if (from < 0)
769 from += size();
770 else if (from >= size())
771 from = size() - 1;
772 if (from >= 0) {
773 const T *b = begin();
774 const T *n = b + from + 1;
775 while (n != b) {
776 if (*--n == t)
777 return n - b;
778 }
779 }
780 return -1;
781}
782
783template <class T>
784template <typename AT>
785Q_INLINE_TEMPLATE bool QVLABase<T>::contains(const AT &t) const
786{
787 const T *b = begin();
788 const T *i = end();
789 while (i != b) {
790 if (*--i == t)
791 return true;
792 }
793 return false;
794}
795
796template <class T>
797Q_OUTOFLINE_TEMPLATE void QVLABase<T>::append_impl(qsizetype prealloc, void *array, const T *abuf, qsizetype increment)
798{
799 Q_ASSERT(abuf || increment == 0);
800 if (increment <= 0)
801 return;
802
803 const qsizetype asize = size() + increment;
804
805 if (asize >= capacity())
806 growBy(prealloc, array, increment);
807
808 if constexpr (QTypeInfo<T>::isComplex)
809 std::uninitialized_copy_n(abuf, increment, end());
810 else
811 memcpy(static_cast<void *>(end()), static_cast<const void *>(abuf), increment * sizeof(T));
812
813 this->s = asize;
814}
815
816template <class T>
817Q_OUTOFLINE_TEMPLATE void QVLABase<T>::assign_impl(qsizetype prealloc, void *array, qsizetype n, const T &t)
818{
819 Q_ASSERT(n >= 0);
820 if (n > capacity()) {
821 reallocate_impl(prealloc, array, 0, capacity()); // clear
822 resize_impl(prealloc, array, n, t);
823 } else {
824 auto mid = (std::min)(n, size());
825 std::fill(data(), data() + mid, t);
826 std::uninitialized_fill(data() + mid, data() + n, t);
827 s = n;
828 erase(data() + n, data() + size());
829 }
830}
831
832template <class T>
833template <typename Iterator>
835void QVLABase<T>::assign_impl(qsizetype prealloc, void *array, Iterator first, Iterator last,
836 std::forward_iterator_tag)
837{
838 // This function only provides the basic exception guarantee.
839 const qsizetype n = std::distance(first, last);
840 if (n > capacity())
841 reallocate_impl(prealloc, array, 0, n); // clear & reserve n
842
843 auto dst = begin();
844
845 if constexpr (!QTypeInfo<T>::isComplex) {
846 // For non-complex types, we prefer a single std::copy() -> memcpy()
847 // call. We can do that because either the default constructor is
848 // trivial (so the lifetime has started) or the copy constructor is
849 // (and won't care what the stored value is). Note that in some cases
850 // dst > end() after this.
851 dst = std::copy(first, last, dst);
852 } else if (n > this->s) {
853 // overwrite existing elements and create new
854 for (qsizetype i = 0; i < this->s; ++i) {
855 *dst = *first;
856 ++first;
857 ++dst;
858 }
859 std::uninitialized_copy_n(first, n - this->s, dst);
860 } else {
861 // overwrite existing elements and destroy tail
862 dst = std::copy(first, last, dst);
863 std::destroy(dst, end());
864 }
865 this->s = n;
866}
867
868template <class T>
869template <typename Iterator>
871void QVLABase<T>::assign_impl(qsizetype prealloc, void *array, Iterator first, Iterator last,
872 std::input_iterator_tag)
873{
874 // This function only provides the basic exception guarantee.
875 auto dst = begin();
876 const auto dend = end();
877 while (true) {
878 if (first == last) { // ran out of elements to assign
879 std::destroy(dst, dend);
880 break;
881 }
882 if (dst == dend) { // ran out of existing elements to overwrite
883 do {
884 emplace_back_impl(prealloc, array, *first);
885 } while (++first != last);
886 return; // size() is already correct (and dst invalidated)!
887 }
888 *dst = *first; // overwrite existing element
889 ++dst;
890 ++first;
891 }
892 this->s = dst - begin();
893}
894
895template <class T>
896template <typename Iterator>
898void QVLABase<T>::assign_impl(qsizetype prealloc, void *array, Iterator first, Iterator last)
899{
900 using Cat = typename std::iterator_traits<Iterator>::iterator_category;
901 assign_impl(prealloc, array, first, last, Cat{});
902}
903
904template <class T>
905Q_OUTOFLINE_TEMPLATE void QVLABase<T>::reallocate_impl(qsizetype prealloc, void *array, qsizetype asize, qsizetype aalloc)
906{
907 Q_ASSERT(aalloc >= asize);
908 Q_ASSERT(data());
909 T *oldPtr = data();
910 qsizetype osize = size();
911 const qsizetype oalloc = capacity();
912
913 const qsizetype copySize = qMin(asize, osize);
914 Q_ASSERT(copySize >= 0);
915
916 if (aalloc != oalloc) {
918 void *newPtr;
919 qsizetype newA;
920 if (aalloc > prealloc) {
921 newPtr = QtPrivate::fittedMalloc(0, &aalloc, sizeof(T));
922 guard.reset(newPtr);
923 Q_CHECK_PTR(newPtr); // could throw
924 // by design: in case of QT_NO_EXCEPTIONS malloc must not fail or it crashes here
925 newA = aalloc;
926 } else {
927 newPtr = array;
928 newA = prealloc;
929 }
930 QtPrivate::q_uninitialized_relocate_n(oldPtr, copySize,
931 reinterpret_cast<T *>(newPtr));
932 // commit:
933 ptr = newPtr;
934 guard.release();
935 a = newA;
936 }
937 s = copySize;
938
939 // destroy remaining old objects
940 if constexpr (QTypeInfo<T>::isComplex) {
941 if (osize > asize)
942 std::destroy(oldPtr + asize, oldPtr + osize);
943 }
944
945 if (oldPtr != reinterpret_cast<T *>(array) && oldPtr != data())
946 QtPrivate::sizedFree(oldPtr, oalloc, sizeof(T));
947}
948
949template <class T>
950Q_OUTOFLINE_TEMPLATE T QVLABase<T>::value(qsizetype i) const
951{
952 if (size_t(i) >= size_t(size()))
953 return T();
954 return operator[](i);
955}
956template <class T>
957Q_OUTOFLINE_TEMPLATE T QVLABase<T>::value(qsizetype i, const T &defaultValue) const
958{
959 return (size_t(i) >= size_t(size())) ? defaultValue : operator[](i);
960}
961
962template <class T, qsizetype Prealloc>
963inline void QVarLengthArray<T, Prealloc>::insert(qsizetype i, T &&t)
964{ verify(i, 0);
965 insert(cbegin() + i, std::move(t)); }
966template <class T, qsizetype Prealloc>
967inline void QVarLengthArray<T, Prealloc>::insert(qsizetype i, const T &t)
968{ verify(i, 0);
969 insert(begin() + i, 1, t); }
970template <class T, qsizetype Prealloc>
971inline void QVarLengthArray<T, Prealloc>::insert(qsizetype i, qsizetype n, const T &t)
972{ verify(i, 0);
973 insert(begin() + i, n, t); }
974template <class T>
975inline void QVLABase<T>::remove(qsizetype i, qsizetype n)
976{ verify(i, n);
977 erase(begin() + i, begin() + i + n); }
978template <class T>
979template <typename AT>
980inline qsizetype QVLABase<T>::removeAll(const AT &t)
981{ return QtPrivate::sequential_erase_with_copy(*this, t); }
982template <class T>
983template <typename AT>
984inline bool QVLABase<T>::removeOne(const AT &t)
985{ return QtPrivate::sequential_erase_one(*this, t); }
986template <class T>
987template <typename Predicate>
988inline qsizetype QVLABase<T>::removeIf(Predicate pred)
989{ return QtPrivate::sequential_erase_if(*this, pred); }
990#if QT_DEPRECATED_SINCE(6, 3)
991template <class T, qsizetype Prealloc>
992inline void QVarLengthArray<T, Prealloc>::prepend(T &&t)
993{ insert(cbegin(), std::move(t)); }
994template <class T, qsizetype Prealloc>
995inline void QVarLengthArray<T, Prealloc>::prepend(const T &t)
996{ insert(begin(), 1, t); }
997#endif
998
999template <class T>
1000inline void QVLABase<T>::replace(qsizetype i, const T &t)
1001{
1002 verify(i);
1003 data()[i] = t;
1004}
1005
1006template <class T>
1007template <typename...Args>
1008Q_OUTOFLINE_TEMPLATE auto QVLABase<T>::emplace_impl(qsizetype prealloc, void *array, const_iterator before, Args &&...args) -> iterator
1009{
1010 Q_ASSERT_X(isValidIterator(before), "QVarLengthArray::insert", "The specified const_iterator argument 'before' is invalid");
1011 Q_ASSERT(size() <= capacity());
1012 Q_ASSERT(capacity() > 0);
1013
1014 const qsizetype offset = qsizetype(before - cbegin());
1015 emplace_back_impl(prealloc, array, std::forward<Args>(args)...);
1016 const auto b = begin() + offset;
1017 const auto e = end();
1018 QtPrivate::q_rotate(b, e - 1, e);
1019 return b;
1020}
1021
1022template <class T>
1023Q_OUTOFLINE_TEMPLATE auto QVLABase<T>::insert_impl(qsizetype prealloc, void *array, const_iterator before, qsizetype n, const T &t) -> iterator
1024{
1025 Q_ASSERT_X(isValidIterator(before), "QVarLengthArray::insert", "The specified const_iterator argument 'before' is invalid");
1026
1027 const qsizetype offset = qsizetype(before - cbegin());
1028 resize_impl(prealloc, array, size() + n, t);
1029 const auto b = begin() + offset;
1030 const auto e = end();
1031 QtPrivate::q_rotate(b, e - n, e);
1032 return b;
1033}
1034
1035template <class T>
1037{
1038 Q_ASSERT_X(isValidIterator(abegin), "QVarLengthArray::erase", "The specified const_iterator argument 'abegin' is invalid");
1039 Q_ASSERT_X(isValidIterator(aend), "QVarLengthArray::erase", "The specified const_iterator argument 'aend' is invalid");
1040
1041 qsizetype f = qsizetype(abegin - cbegin());
1042 qsizetype l = qsizetype(aend - cbegin());
1043 qsizetype n = l - f;
1044
1045 if (n == 0) // avoid UB in std::move() below
1046 return data() + f;
1047
1048 Q_ASSERT(n > 0); // aend must be reachable from abegin
1049
1050 if constexpr (!QTypeInfo<T>::isRelocatable) {
1051 std::move(begin() + l, end(), QT_MAKE_CHECKED_ARRAY_ITERATOR(begin() + f, size() - f));
1052 std::destroy(end() - n, end());
1053 } else {
1054 std::destroy(abegin, aend);
1055 memmove(static_cast<void *>(data() + f), static_cast<const void *>(data() + l), (size() - l) * sizeof(T));
1056 }
1057 this->s -= n;
1058 return data() + f;
1059}
1060
1061#ifdef Q_QDOC
1062// Fake definitions for qdoc, only the redeclaration is used.
1063template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
1064bool operator==(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r)
1065{ return bool{}; }
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{}; }
1081#endif
1082
1083template <typename T, qsizetype Prealloc>
1084size_t qHash(const QVarLengthArray<T, Prealloc> &key, size_t seed = 0)
1085 noexcept(QtPrivate::QNothrowHashable_v<T>)
1086{
1087 return key.hash(seed);
1088}
1089
1090template <typename T, qsizetype Prealloc, typename AT>
1091qsizetype erase(QVarLengthArray<T, Prealloc> &array, const AT &t)
1092{
1093 return array.removeAll(t);
1094}
1095
1096template <typename T, qsizetype Prealloc, typename Predicate>
1097qsizetype erase_if(QVarLengthArray<T, Prealloc> &array, Predicate pred)
1098{
1099 return array.removeIf(pred);
1100}
1101
1102QT_END_NAMESPACE
1103
1104#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:59
int initFrom(const QMessageLogContext &logContext)
void populateBacktrace(int frameCount)
QInternalMessageLogContext(const QMessageLogContext &logContext, const QLoggingCategory &categoryOverride)
Definition qlogging_p.h:65
std::optional< BacktraceStorage > backtrace
Definition qlogging_p.h:57
static constexpr int DefaultBacktraceDepth
Definition qlogging_p.h:47
Definition qlist.h:81
\inmodule QtCore
Definition qlogging.h:43
constexpr QMessageLogContext(const char *fileName, int lineNumber, const char *functionName, const char *categoryName) noexcept
Definition qlogging.h:48
const char * category
Definition qlogging.h:55
constexpr QMessageLogContext() noexcept=default
const char * function
Definition qlogging.h:54
const char * file
Definition qlogging.h:53
\inmodule QtCore
Definition qlogging.h:73
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:525
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:511
QDebug info(const QLoggingCategory &cat) const
Logs an informational message into the category cat using a QDebug stream.
Definition qlogging.cpp:614
QDebug info() const
Logs an informational message using a QDebug stream.
Definition qlogging.cpp:600
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
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:408
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:262
static const char endifTokenC[]
static bool isDefaultCategory(const char *category)
Definition qlogging.cpp:954
static const char messageTokenC[]
static bool qt_append_thread_name_to(QString &message)
Definition qlogging.cpp:247
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:152
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:138
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:186
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:287
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:340
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:110
QT_BEGIN_NAMESPACE Q_NORETURN void qAbort()
Definition qassert.cpp:24
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:161
#define QT_MESSAGELOG_FILE
Definition qlogging.h:159
#define QT_MESSAGE_LOGGER_NORETURN
Definition qlogging.h:69
#define QT_MESSAGELOG_LINE
Definition qlogging.h:160
Q_CORE_EXPORT void qSetMessagePattern(const QString &messagePattern)
#define QT_MESSAGELOGCONTEXT
Definition qlogging.h:154
QtMsgType
Definition qlogging.h:29
@ QtCriticalMsg
Definition qlogging.h:33
@ QtFatalMsg
Definition qlogging.h:34
@ QtDebugMsg
Definition qlogging.h:30
Q_CORE_EXPORT void qt_message_output(QtMsgType, const QMessageLogContext &context, const QString &message)
void(* QtMessageHandler)(QtMsgType, const QMessageLogContext &, const QString &)
Definition qlogging.h:196
#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