4#ifndef QVARLENGTHARRAY_H
5#define QVARLENGTHARRAY_H
8#pragma qt_class(QVarLengthArray)
9#pragma qt_sync_stop_processing
12#include <QtCore/qcontainerfwd.h>
13#include <QtCore/qglobal.h>
14#include <QtCore/qalgorithms.h>
15#include <QtCore/qcontainertools_impl.h>
16#include <QtCore/qhashfunctions.h>
19#include <initializer_list>
21#include <QtCore/q20memory.h>
29template <
size_t Size,
size_t Align, qsizetype Prealloc>
32 template <
size_t>
class print;
41 static_assert(std::is_same_v<print<
sizeof(std::aligned_storage_t<Size, Align>[Prealloc])>,
42 print<
sizeof(
array)>>);
74 constexpr bool empty() const noexcept {
return size() == 0; }
84 T *
data() noexcept {
return static_cast<T *
>(
ptr); }
85 const T *
data() const noexcept {
return static_cast<T *
>(
ptr); }
146 template <
typename AT = T>
148 template <
typename AT = T>
150 template <
typename AT = T>
169 template <
typename AT = T>
171 template <
typename AT = T>
173 template <
typename Predicate>
186 size_t hash(
size_t seed)
const noexcept(QtPrivate::QNothrowHashable_v<T>)
193 template <
typename...Args>
202 template <
typename...Args>
207 template <
typename S>
212 template <
typename S>
227 while (
size() < sz) {
237 while (
size() < sz) {
247 template <
typename Iterator>
252 const std::less<const T *> less = {};
258template<
class T, qsizetype Prealloc>
261 : public
QVLAStorage<sizeof(T), alignof(T), Prealloc>,
265 public
QVLAStorage<sizeof(T), alignof(T), Prealloc>
268 template <
class S, qsizetype Prealloc2>
272 static_assert(Prealloc > 0,
"QVarLengthArray Prealloc must be greater than 0.");
273 static_assert(std::is_nothrow_destructible_v<T>,
"Types with throwing destructors are not supported in Qt containers.");
276 template <
typename U>
277 using if_copyable = std::enable_if_t<std::is_copy_constructible_v<U>,
bool>;
278 template <
typename InputIterator>
304 template <
typename U = T, if_copyable<U> = true>
319 noexcept(std::is_nothrow_move_constructible_v<T>)
322 const auto otherInlineStorage =
reinterpret_cast<T*
>(
other.array);
323 if (
data() == otherInlineStorage) {
333 other.ptr = otherInlineStorage;
341 template <
typename InputIterator, if_input_iterator<InputIterator> = true>
346 std::copy(
first,
last, std::back_inserter(*
this));
353 if (
data() !=
reinterpret_cast<T *
>(this->
array))
358 if (
this != &
other) {
366 noexcept(std::is_nothrow_move_constructible_v<T>)
373 const auto otherInlineStorage =
other.array;
374 if (
other.ptr != otherInlineStorage) {
376 this->
a = std::exchange(
other.a, Prealloc);
377 this->
ptr = std::exchange(
other.ptr, otherInlineStorage);
382 this->
s = std::exchange(
other.s, 0);
421 template <
typename U = T, if_copyable<U> = true>
438 template <
typename AT = T>
440 template <
typename AT = T>
442 template <
typename AT = T>
461 using Base::operator[];
488 {
append(std::move(
t));
return *
this; }
492 {
append(std::move(
t));
return *
this; }
494#if QT_DEPRECATED_SINCE(6, 3)
506 template <
typename InputIterator, if_input_iterator<InputIterator> = true>
515 template <
typename AT = T>
517 template <
typename AT = T>
519 template <
typename Predicate>
529 inline T *
data() {
return this->
ptr; }
530 inline const T *
data()
const {
return this->
ptr; }
583 inline const T &
front()
const {
return first(); }
585 inline const T &
back()
const {
return last(); }
591 template <
typename...Args>
594 template <
typename...Args>
600 template <
typename T, qsizetype Prealloc1, qsizetype Prealloc2>
602 template <
typename T, qsizetype Prealloc1, qsizetype Prealloc2>
604 template <
typename T, qsizetype Prealloc1, qsizetype Prealloc2>
606 template <
typename T, qsizetype Prealloc1, qsizetype Prealloc2>
608 template <
typename T, qsizetype Prealloc1, qsizetype Prealloc2>
610 template <
typename T, qsizetype Prealloc1, qsizetype Prealloc2>
613 template <
typename U = T, qsizetype Prealloc2 = Prealloc>
friend
619 template <
typename U = T, qsizetype Prealloc2 = Prealloc>
friend
625 template <
typename U = T, qsizetype Prealloc2 = Prealloc>
friend
627 noexcept(
noexcept(std::lexicographical_compare(lhs.begin(), lhs.end(),
628 rhs.begin(), rhs.end())))
630 return lhs.less_than(rhs);
633 template <
typename U = T, qsizetype Prealloc2 = Prealloc>
friend
635 noexcept(
noexcept(lhs < rhs))
640 template <
typename U = T, qsizetype Prealloc2 = Prealloc>
friend
642 noexcept(
noexcept(lhs < rhs))
647 template <
typename U = T, qsizetype Prealloc2 = Prealloc>
friend
649 noexcept(
noexcept(lhs < rhs))
656 template <
typename U, qsizetype Prealloc2>
659 template <
typename U, qsizetype Prealloc2>
669template <
typename InputIterator,
670 typename ValueType =
typename std::iterator_traits<InputIterator>::value_type,
674template <
class T, qsizetype Prealloc>
678 Q_ASSERT_X(asize >= 0,
"QVarLengthArray::QVarLengthArray(qsizetype)",
679 "Size must be greater than or equal to 0.");
684 if (asize > Prealloc) {
685 this->
ptr = malloc(asize *
sizeof(T));
690 std::uninitialized_default_construct_n(
data(), asize);
695template <
typename AT>
701 const T *
n =
data() + from - 1;
711template <
typename AT>
716 else if (from >=
size())
720 const T *
n =
b + from + 1;
730template <
typename AT>
757 memcpy(
static_cast<void *
>(
end()),
static_cast<const void *
>(abuf),
increment *
sizeof(T));
770 auto mid = (std::min)(
n,
size());
772 std::uninitialized_fill(
data() + mid,
data() +
n,
t);
779template <
typename Iterator>
783 constexpr bool IsFwdIt =
784 std::is_convertible_v<typename std::iterator_traits<Iterator>::iterator_category,
785 std::forward_iterator_tag>;
786 if constexpr (IsFwdIt) {
793 const auto dend =
end();
796 std::destroy(
dst, dend);
800 if constexpr (IsFwdIt) {
826 Q_ASSUME(copySize >= 0);
832 if (aalloc > prealloc) {
833 newPtr = malloc(aalloc *
sizeof(T));
843 reinterpret_cast<T *
>(newPtr));
854 std::destroy(oldPtr + asize, oldPtr + osize);
857 if (oldPtr !=
reinterpret_cast<T *
>(
array) && oldPtr !=
data())
864 if (
size_t(
i) >=
size_t(
size()))
874template <
class T, qsizetype Prealloc>
878template <
class T, qsizetype Prealloc>
882template <
class T, qsizetype Prealloc>
891template <
typename AT>
895template <
typename AT>
899template <
typename Predicate>
902#if QT_DEPRECATED_SINCE(6, 3)
903template <
class T, qsizetype Prealloc>
906template <
class T, qsizetype Prealloc>
919template <
typename...Args>
922 Q_ASSERT_X(isValidIterator(before),
"QVarLengthArray::insert",
"The specified const_iterator argument 'before' is invalid");
929 const auto e =
end();
937 Q_ASSERT_X(isValidIterator(before),
"QVarLengthArray::insert",
"The specified const_iterator argument 'before' is invalid");
942 const auto e =
end();
950 Q_ASSERT_X(isValidIterator(abegin),
"QVarLengthArray::insert",
"The specified const_iterator argument 'abegin' is invalid");
951 Q_ASSERT_X(isValidIterator(aend),
"QVarLengthArray::insert",
"The specified const_iterator argument 'aend' is invalid");
964 std::destroy(
end() -
n,
end());
966 memmove(
static_cast<void *
>(
data() +
f),
static_cast<const void *
>(
data() + l), (
size() - l) *
sizeof(T));
974template <
typename T, qsizetype Prealloc1, qsizetype Prealloc2>
977template <
typename T, qsizetype Prealloc1, qsizetype Prealloc2>
980template <
typename T, qsizetype Prealloc1, qsizetype Prealloc2>
983template <
typename T, qsizetype Prealloc1, qsizetype Prealloc2>
986template <
typename T, qsizetype Prealloc1, qsizetype Prealloc2>
989template <
typename T, qsizetype Prealloc1, qsizetype Prealloc2>
994template <
typename T, qsizetype Prealloc>
996 noexcept(
QtPrivate::QNothrowHashable_v<T>)
1001template <
typename T, qsizetype Prealloc,
typename AT>
1004 return array.removeAll(
t);
1007template <
typename T, qsizetype Prealloc,
typename Predicate>
1010 return array.removeIf(pred);
constexpr size_type capacity() const noexcept
Q_ALWAYS_INLINE constexpr void verify(qsizetype pos=0, qsizetype n=1) const
constexpr bool empty() const noexcept
std::unique_ptr< void, free_deleter > malloced_ptr
constexpr size_type size() const noexcept
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
std::reverse_iterator< iterator > reverse_iterator
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
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
iterator erase(const_iterator begin, const_iterator end)
const_reference front() const
bool isValidIterator(const const_iterator &i) const
const_iterator cend() const noexcept
const value_type * const_pointer
const T * data() const noexcept
const_reverse_iterator crbegin() const noexcept
std::reverse_iterator< const_iterator > const_reverse_iterator
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)
void assign_impl(qsizetype prealloc, void *array, Iterator first, Iterator last)
reference operator[](qsizetype idx)
size_t hash(size_t seed) const noexcept(QtPrivate::QNothrowHashable_v< T >)
const_iterator end() const noexcept
qsizetype indexOf(const AT &t, qsizetype from=0) const
const_iterator begin() const noexcept
qsizetype removeAll(const AT &t)
const value_type & const_reference
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
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)
QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED
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)
typename Base::pointer pointer
qsizetype removeIf(Predicate pred)
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
reverse_iterator rbegin() noexcept
const_iterator cbegin() const noexcept
typename Base::const_pointer const_pointer
QVarLengthArray(qsizetype sz, const T &v)
bool removeOne(const AT &t)
QVarLengthArray(const QVarLengthArray &other)
QVarLengthArray(qsizetype size)
iterator insert(const_iterator before, qsizetype n, const T &x)
QVarLengthArray(InputIterator first, InputIterator last)
const_iterator cend() const noexcept
iterator emplace(const_iterator pos, Args &&...args)
typename Base::reference reference
typename Base::size_type size_type
const_reverse_iterator crbegin() const noexcept
void replace(qsizetype i, const T &t)
void insert(qsizetype i, T &&t)
QVarLengthArray(QVarLengthArray &&other) noexcept(std::is_nothrow_move_constructible_v< T >)
friend class QVarLengthArray
QVarLengthArray & operator=(QVarLengthArray &&other) noexcept(std::is_nothrow_move_constructible_v< T >)
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
qsizetype removeAll(const AT &t)
typename Base::difference_type difference_type
void append(const T *buf, qsizetype sz)
QVarLengthArray< T, Prealloc > & operator=(std::initializer_list< T > list)
QVarLengthArray(std::initializer_list< T > args)
iterator insert(const_iterator before, const T &x)
typename Base::reverse_iterator reverse_iterator
const_reverse_iterator crend() const noexcept
void insert(qsizetype i, const T &t)
const T * constData() const
typename Base::const_reverse_iterator const_reverse_iterator
reverse_iterator rend() noexcept
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)
list append(new Employee("Blackpool", "Stephen"))
cache insert(employee->id(), employee)
Combined button and popup list for selecting options.
std::enable_if_t< std::conjunction_v< QTypeTraits::has_operator_equal< T >... >, bool > compare_eq_result
std::enable_if_t< std::conjunction_v< QTypeTraits::has_operator_less_than< T >... >, bool > compare_lt_result
QT_WARNING_POP void q_rotate(T *first, T *mid, T *last)
void q_uninitialized_relocate_n(T *first, N n, T *out)
static constexpr bool q_points_into_range(const T *p, const T *b, const T *e, Cmp less={}) noexcept
auto sequential_erase_one(Container &c, const T &t)
auto sequential_erase_if(Container &c, Predicate &pred)
auto sequential_erase_with_copy(Container &c, const T &t)
typename std::enable_if< std::is_convertible< typename std::iterator_traits< Iterator >::iterator_category, std::input_iterator_tag >::value, bool >::type IfIsInputIterator
void reserveIfForwardIterator(Container *, InputIterator, InputIterator)
T * construct_at(T *ptr, Args &&... args)
#define QT_MAKE_CHECKED_ARRAY_ITERATOR(x, N)
constexpr bool operator!=(const timespec &t1, const timespec &t2)
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
size_t qHashRange(InputIterator first, InputIterator last, size_t seed=0) noexcept(noexcept(qHash(*first)))
static ControlElement< T > * ptr(QWidget *widget)
constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qMax(const T &a, const T &b)
static bool contains(const QJsonArray &haystack, unsigned needle)
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLint GLint GLint GLint GLint x
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLuint GLenum GLsizei const GLchar * buf
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint GLintptr offset
bool operator>(const QPoint &a, const QPoint &b)
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
bool operator==(const QRandomGenerator &rng1, const QRandomGenerator &rng2)
#define Q_ASSERT_X(cond, x, msg)
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
static bool operator<(const QSettingsIniKey &k1, const QSettingsIniKey &k2)
#define QT_DEPRECATED_VERSION_X_6_3(text)
#define QT_VERSION_CHECK(major, minor, patch)
static bool equal(const QChar *a, int l, const char *b)
bool operator<=(const QUuid &lhs, const QUuid &rhs) noexcept
bool operator>=(const QUuid &lhs, const QUuid &rhs) noexcept
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 >)
QtConcurrent::task([]{ qDebug("Hello, world!");}).spawn(FutureResult void increment(QPromise< int > &promise, int i)
[10]
Q_CHECK_PTR(a=new int[80])
if(qFloatDistance(a, b)<(1<< 7))
[0]
settings remove("monkey")
void operator()(void *p) const noexcept