40 #ifndef QVARLENGTHARRAY_H
41 #define QVARLENGTHARRAY_H
44 #pragma qt_class(QVarLengthArray)
45 #pragma qt_sync_stop_processing
48 #include <QtCore/qcontainerfwd.h>
49 #include <QtCore/qglobal.h>
50 #include <QtCore/qalgorithms.h>
51 #include <QtCore/qcontainertools_impl.h>
52 #include <QtCore/qhashfunctions.h>
55 #include <initializer_list>
65 template <
size_t Size,
size_t Align, qsizetype Prealloc>
68 template <
size_t>
class print;
77 static_assert(std::is_same_v<print<
sizeof(std::aligned_storage_t<Size, Align>[Prealloc])>,
78 print<
sizeof(
array)>>);
181 template <
typename AT = T>
183 template <
typename AT = T>
185 template <
typename AT = T>
204 template <
typename AT = T>
206 template <
typename AT = T>
208 template <
typename Predicate>
214 size_t hash(
size_t seed)
const noexcept(QtPrivate::QNothrowHashable_v<T>)
219 template <
typename...Args>
228 template <
typename...Args>
233 template <
typename S>
238 template <
typename S>
251 const std::less<const T *> less = {};
257 template<
class T, qsizetype Prealloc>
260 public QVLAStorage<sizeof(T), alignof(T), Prealloc>
262 template <
class S, qsizetype Prealloc2>
266 static_assert(std::is_nothrow_destructible_v<T>,
"Types with throwing destructors are not supported in Qt containers.");
298 noexcept(std::is_nothrow_move_constructible_v<T>)
301 const auto otherInlineStorage =
reinterpret_cast<T*
>(
other.array);
302 if (
data() == otherInlineStorage) {
312 other.ptr = otherInlineStorage;
320 template <
typename InputIterator, QtPrivate::IfIsInputIterator<InputIterator> = true>
325 std::copy(
first,
last, std::back_inserter(*
this));
332 if (
data() !=
reinterpret_cast<T *
>(this->
array))
337 if (
this != &
other) {
345 noexcept(std::is_nothrow_move_constructible_v<T>)
352 const auto otherInlineStorage =
other.array;
353 if (
other.ptr != otherInlineStorage) {
355 this->
a = std::exchange(
other.a, Prealloc);
356 this->
ptr = std::exchange(
other.ptr, otherInlineStorage);
361 this->
s = std::exchange(
other.s, 0);
411 template <
typename AT = T>
413 template <
typename AT = T>
415 template <
typename AT = T>
434 using Base::operator[];
461 {
append(std::move(
t));
return *
this; }
465 {
append(std::move(
t));
return *
this; }
467 #if QT_DEPRECATED_SINCE(6, 3)
479 template <
typename AT = T>
481 template <
typename AT = T>
483 template <
typename Predicate>
493 inline T *
data() {
return this->
ptr; }
494 inline const T *
data()
const {
return this->
ptr; }
549 inline const T &
back()
const {
return last(); }
555 template <
typename...Args>
558 template <
typename...Args>
564 template <
typename T, qsizetype Prealloc1, qsizetype Prealloc2>
566 template <
typename T, qsizetype Prealloc1, qsizetype Prealloc2>
568 template <
typename T, qsizetype Prealloc1, qsizetype Prealloc2>
570 template <
typename T, qsizetype Prealloc1, qsizetype Prealloc2>
572 template <
typename T, qsizetype Prealloc1, qsizetype Prealloc2>
574 template <
typename T, qsizetype Prealloc1, qsizetype Prealloc2>
577 template <
typename U = T, qsizetype Prealloc2 = Prealloc>
friend
583 template <
typename U = T, qsizetype Prealloc2 = Prealloc>
friend
589 template <
typename U = T, qsizetype Prealloc2 = Prealloc>
friend
591 noexcept(noexcept(std::lexicographical_compare(lhs.begin(), lhs.end(),
594 return lhs.less_than(
rhs);
597 template <
typename U = T, qsizetype Prealloc2 = Prealloc>
friend
599 noexcept(noexcept(lhs <
rhs))
604 template <
typename U = T, qsizetype Prealloc2 = Prealloc>
friend
606 noexcept(noexcept(lhs <
rhs))
611 template <
typename U = T, qsizetype Prealloc2 = Prealloc>
friend
613 noexcept(noexcept(lhs <
rhs))
620 template <
typename U, qsizetype Prealloc2>
623 template <
typename U, qsizetype Prealloc2>
633 template <
typename InputIterator,
638 template <
class T, qsizetype Prealloc>
642 static_assert(Prealloc > 0,
"QVarLengthArray Prealloc must be greater than 0.");
643 Q_ASSERT_X(
size() >= 0,
"QVarLengthArray::QVarLengthArray()",
"Size must be greater than or equal to 0.");
644 if (
size() > Prealloc) {
645 this->
ptr = malloc(
size() *
sizeof(
T));
660 template <
typename AT>
666 const T *
n =
data() + from - 1;
676 template <
typename AT>
681 else if (from >=
size())
685 const T *
n =
b + from + 1;
695 template <
typename AT>
722 memcpy(
static_cast<void *
>(
end()),
static_cast<const void *
>(abuf),
increment *
sizeof(
T));
735 const qsizetype copySize = qMin(asize, osize);
742 if (aalloc > prealloc) {
743 newPtr = malloc(aalloc *
sizeof(
T));
753 reinterpret_cast<T *
>(newPtr));
767 if (oldPtr !=
reinterpret_cast<T *
>(
array) && oldPtr !=
data())
772 while (
size() < asize) {
785 if (
size_t(
i) >=
size_t(
size()))
795 template <
class T, qsizetype Prealloc>
799 template <
class T, qsizetype Prealloc>
803 template <
class T, qsizetype Prealloc>
812 template <
typename AT>
816 template <
typename AT>
820 template <
typename Predicate>
823 #if QT_DEPRECATED_SINCE(6, 3)
824 template <
class T, qsizetype Prealloc>
827 template <
class T, qsizetype Prealloc>
840 template <
typename...Args>
843 Q_ASSERT_X(isValidIterator(before),
"QVarLengthArray::insert",
"The specified const_iterator argument 'before' is invalid");
856 new (--
j)
T(std::move(*--
i));
858 *--
j = std::move(*--
i);
859 *
b =
T(std::forward<Args>(
args)...);
861 new (
b)
T(std::forward<Args>(
args)...);
865 memmove(
static_cast<void *
>(
b + 1),
static_cast<const void *
>(
b), (
size() -
offset) *
sizeof(
T));
866 new (
b)
T(std::forward<Args>(
args)...);
875 Q_ASSERT_X(isValidIterator(before),
"QVarLengthArray::insert",
"The specified const_iterator argument 'before' is invalid");
904 Q_ASSERT_X(isValidIterator(abegin),
"QVarLengthArray::insert",
"The specified const_iterator argument 'abegin' is invalid");
905 Q_ASSERT_X(isValidIterator(aend),
"QVarLengthArray::insert",
"The specified const_iterator argument 'aend' is invalid");
928 template <
typename T, qsizetype Prealloc1, qsizetype Prealloc2>
931 template <
typename T, qsizetype Prealloc1, qsizetype Prealloc2>
934 template <
typename T, qsizetype Prealloc1, qsizetype Prealloc2>
937 template <
typename T, qsizetype Prealloc1, qsizetype Prealloc2>
940 template <
typename T, qsizetype Prealloc1, qsizetype Prealloc2>
943 template <
typename T, qsizetype Prealloc1, qsizetype Prealloc2>
948 template <
typename T, qsizetype Prealloc>
952 return key.hash(seed);
955 template <
typename T, qsizetype Prealloc,
typename AT>
958 return array.removeAll(
t);
961 template <
typename T, qsizetype Prealloc,
typename Predicate>
964 return array.removeIf(pred);
small capitals from c petite p scientific i
[1]
template< typename T > qsizetype erase(QByteArray &ba, const T &t)
template< typename Predicate > qsizetype erase_if(QByteArray &ba, Predicate pred)
bool operator<(const QElapsedTimer &lhs, const QElapsedTimer &rhs) noexcept
template< typename Enum > bool operator!=(Enum lhs, QFlags< Enum > rhs)
template< typename Enum > size_t qHash(QFlags< Enum > flags, size_t seed=0) noexcept
template< typename Enum > bool operator==(Enum lhs, QFlags< Enum > rhs)
bool operator<=(const QUuid &lhs, const QUuid &rhs)
bool operator>=(const QUuid &lhs, const QUuid &rhs)
constexpr size_type capacity() const noexcept
constexpr Q_ALWAYS_INLINE 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
bool removeOne(const AT &t)
bool equal(const QVLABase< S > &other) const
iterator erase(const_iterator begin, const_iterator end)
const_reference front() const
const T * data() const noexcept
bool isValidIterator(const const_iterator &i) const
const_iterator cend() const noexcept
const value_type * const_pointer
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)
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
iterator begin() noexcept
iterator emplace_impl(qsizetype prealloc, void *array, const_iterator pos, Args &&...arg)
QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED
char array[Prealloc *(Align > Size ? Align :Size)]
friend QTypeTraits::compare_eq_result< U > operator!=(const QVarLengthArray< T, Prealloc > &l, const QVarLengthArray< T, Prealloc2 > &r)
void remove(qsizetype i, qsizetype n=1)
friend QTypeTraits::compare_lt_result< U > operator<=(const QVarLengthArray< T, Prealloc > &lhs, const QVarLengthArray< T, Prealloc2 > &rhs) noexcept(noexcept(lhs< rhs))
iterator insert(const_iterator before, T &&x)
value_type value(qsizetype i) const
friend QTypeTraits::compare_lt_result< U > operator>(const QVarLengthArray< T, Prealloc > &lhs, const QVarLengthArray< T, Prealloc2 > &rhs) noexcept(noexcept(lhs< rhs))
qsizetype removeIf(Predicate pred)
void resize(qsizetype sz)
typename Base::iterator iterator
reverse_iterator rbegin() noexcept
const_iterator cbegin() const noexcept
qsizetype lastIndexOf(const AT &t, qsizetype from=-1) const
bool removeOne(const AT &t)
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())))
QVarLengthArray(const QVarLengthArray &other)
QVarLengthArray(qsizetype size)
iterator insert(const_iterator before, qsizetype n, const T &x)
QVarLengthArray(InputIterator first, InputIterator last)
iterator erase(const_iterator begin, const_iterator end)
const_iterator cend() const noexcept
iterator emplace(const_iterator pos, Args &&...args)
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
typename Base::const_iterator const_iterator
qsizetype indexOf(const AT &t, qsizetype from=0) const
const T * constData() const
const_iterator constEnd() const
friend QTypeTraits::compare_eq_result< U > operator==(const QVarLengthArray< T, Prealloc > &l, const QVarLengthArray< T, Prealloc2 > &r)
QVarLengthArray< T, Prealloc > & operator=(const QVarLengthArray< T, Prealloc > &other)
qsizetype removeAll(const AT &t)
const T & at(qsizetype idx) const
void append(const T *buf, qsizetype sz)
QVarLengthArray & operator=(QVarLengthArray &&other) noexcept(std::is_nothrow_move_constructible_v< T >)
QVarLengthArray< T, Prealloc > & operator+=(const T &t)
QVarLengthArray(std::initializer_list< T > args)
QVarLengthArray< T, Prealloc > & operator<<(const T &t)
iterator insert(const_iterator before, const T &x)
typename Base::reverse_iterator reverse_iterator
friend QTypeTraits::compare_lt_result< U > operator>=(const QVarLengthArray< T, Prealloc > &lhs, const QVarLengthArray< T, Prealloc2 > &rhs) noexcept(noexcept(lhs< rhs))
const_reverse_iterator crend() const noexcept
void insert(qsizetype i, const T &t)
bool contains(const AT &t) const
typename Base::const_reverse_iterator const_reverse_iterator
reverse_iterator rend() noexcept
T & emplace_back(Args &&...args)
void push_back(const T &t)
auto constBegin() const -> const_iterator
QVarLengthArray() noexcept
QVarLengthArray< T, Prealloc > & operator=(std::initializer_list< T > list)
void reserve(qsizetype sz)
iterator begin() noexcept
void insert(qsizetype i, qsizetype n, const T &t)
QVarLengthArray< T, Prealloc > & operator+=(T &&t)
map insert("Paris", "France")
auto it unsigned count const
Generic::PredicateMatcher< T > Predicate(std::function< bool(T const &)> const &predicate, std::string const &description="")
typename C::value_type value_type
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
void q_uninitialized_relocate_n(T *first, N n, T *out)
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)
constexpr bool QNothrowHashable_v
decltype(auto) cbegin(const T &t)
void *PRIV() memmove(void *d, const void *s, size_t n)
#define QT_MAKE_CHECKED_ARRAY_ITERATOR(x, N)
constexpr bool operator>(const QFixed &f, int i)
#define QT_DEPRECATED_VERSION_X_6_3(text)
size_t qHashRange(InputIterator first, InputIterator last, size_t seed=0) noexcept(noexcept(qHash(*first)))
GLboolean GLboolean GLboolean b
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
#define Q_ASSERT_X(cond, x, msg)
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
QVarLengthArray(InputIterator, InputIterator) -> QVarLengthArray< ValueType >
HB_EXTERN hb_font_get_glyph_func_t void hb_destroy_func_t destroy
QtConcurrent::task([]{ qDebug("Hello, world!");}).spawn(FutureResult void increment(QPromise< int > &promise, int i)
[10]
Q_CHECK_PTR(a=new int[80])
void operator()(void *p) const noexcept