summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qlist.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/tools/qlist.h')
-rw-r--r--src/corelib/tools/qlist.h331
1 files changed, 199 insertions, 132 deletions
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h
index 0329dd37da..89e0e3f380 100644
--- a/src/corelib/tools/qlist.h
+++ b/src/corelib/tools/qlist.h
@@ -1,42 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Copyright (C) 2019 Intel Corporation
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// Copyright (C) 2019 Intel Corporation
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QLIST_H
#define QLIST_H
@@ -46,12 +10,15 @@
#include <QtCore/qhashfunctions.h>
#include <QtCore/qiterator.h>
#include <QtCore/qcontainertools_impl.h>
+#include <QtCore/qnamespace.h>
#include <functional>
#include <limits>
#include <initializer_list>
#include <type_traits>
+class tst_QList;
+
QT_BEGIN_NAMESPACE
namespace QtPrivate {
@@ -92,6 +59,10 @@ public:
template <> struct QListSpecialMethods<QByteArray>;
template <> struct QListSpecialMethods<QString>;
+#if !defined(QT_STRICT_QLIST_ITERATORS) && (QT_VERSION >= QT_VERSION_CHECK(6, 6, 0)) && !defined(Q_OS_WIN)
+#define QT_STRICT_QLIST_ITERATORS
+#endif
+
#ifdef Q_QDOC // define QVector for QDoc
template<typename T> class QVector : public QList<T> {};
#endif
@@ -107,10 +78,15 @@ class QList
using DataPointer = QArrayDataPointer<T>;
class DisableRValueRefs {};
+ friend class ::tst_QList;
+
DataPointer d;
template <typename V, typename U> friend qsizetype QtPrivate::indexOf(const QList<V> &list, const U &u, qsizetype from) noexcept;
template <typename V, typename U> friend qsizetype QtPrivate::lastIndexOf(const QList<V> &list, const U &u, qsizetype from) noexcept;
+ // This alias prevents the QtPrivate namespace from being exposed into the docs.
+ template <typename InputIterator>
+ using if_input_iterator = QtPrivate::IfIsInputIterator<InputIterator>;
public:
using Type = T;
@@ -129,24 +105,30 @@ public:
using rvalue_ref = T &&;
#endif
+ class const_iterator;
class iterator {
+ friend class QList<T>;
+ friend class const_iterator;
T *i = nullptr;
+#ifdef QT_STRICT_QLIST_ITERATORS
+ inline constexpr explicit iterator(T *n) : i(n) {}
+#endif
+
public:
using difference_type = qsizetype;
using value_type = T;
- // libstdc++ shipped with gcc < 11 does not have a fix for defect LWG 3346
-#if __cplusplus >= 202002L && (!defined(_GLIBCXX_RELEASE) || _GLIBCXX_RELEASE >= 11)
- using iterator_category = std::contiguous_iterator_tag;
+#ifdef QT_COMPILER_HAS_LWG3346
+ using iterator_concept = std::contiguous_iterator_tag;
using element_type = value_type;
-#else
- using iterator_category = std::random_access_iterator_tag;
#endif
-
+ using iterator_category = std::random_access_iterator_tag;
using pointer = T *;
using reference = T &;
inline constexpr iterator() = default;
- inline iterator(T *n) : i(n) {}
+#ifndef QT_STRICT_QLIST_ITERATORS
+ inline constexpr explicit iterator(T *n) : i(n) {}
+#endif
inline T &operator*() const { return *i; }
inline T *operator->() const { return i; }
inline T &operator[](qsizetype j) const { return *(i + j); }
@@ -156,39 +138,68 @@ public:
inline constexpr bool operator<=(iterator other) const { return i <= other.i; }
inline constexpr bool operator>(iterator other) const { return i > other.i; }
inline constexpr bool operator>=(iterator other) const { return i >= other.i; }
+ inline constexpr bool operator==(const_iterator o) const { return i == o.i; }
+ inline constexpr bool operator!=(const_iterator o) const { return i != o.i; }
+ inline constexpr bool operator<(const_iterator other) const { return i < other.i; }
+ inline constexpr bool operator<=(const_iterator other) const { return i <= other.i; }
+ inline constexpr bool operator>(const_iterator other) const { return i > other.i; }
+ inline constexpr bool operator>=(const_iterator other) const { return i >= other.i; }
inline constexpr bool operator==(pointer p) const { return i == p; }
inline constexpr bool operator!=(pointer p) const { return i != p; }
inline iterator &operator++() { ++i; return *this; }
- inline iterator operator++(int) { T *n = i; ++i; return n; }
- inline iterator &operator--() { i--; return *this; }
- inline iterator operator--(int) { T *n = i; i--; return n; }
- inline iterator &operator+=(qsizetype j) { i+=j; return *this; }
- inline iterator &operator-=(qsizetype j) { i-=j; return *this; }
- inline iterator operator+(qsizetype j) const { return iterator(i+j); }
- inline iterator operator-(qsizetype j) const { return iterator(i-j); }
- friend inline iterator operator+(qsizetype j, iterator k) { return k + j; }
+ inline iterator operator++(int) { auto copy = *this; ++*this; return copy; }
+ inline iterator &operator--() { --i; return *this; }
+ inline iterator operator--(int) { auto copy = *this; --*this; return copy; }
inline qsizetype operator-(iterator j) const { return i - j.i; }
+#if QT_DEPRECATED_SINCE(6, 3) && !defined(QT_STRICT_QLIST_ITERATORS)
+ QT_DEPRECATED_VERSION_X_6_3("Use operator* or operator-> rather than relying on "
+ "the implicit conversion between a QList/QVector::iterator "
+ "and a raw pointer")
inline operator T*() const { return i; }
+
+ template <typename Int> std::enable_if_t<std::is_integral_v<Int>, iterator>
+ &operator+=(Int j) { i+=j; return *this; }
+ template <typename Int> std::enable_if_t<std::is_integral_v<Int>, iterator>
+ &operator-=(Int j) { i-=j; return *this; }
+ template <typename Int> std::enable_if_t<std::is_integral_v<Int>, iterator>
+ operator+(Int j) const { return iterator(i+j); }
+ template <typename Int> std::enable_if_t<std::is_integral_v<Int>, iterator>
+ operator-(Int j) const { return iterator(i-j); }
+ template <typename Int> friend std::enable_if_t<std::is_integral_v<Int>, iterator>
+ operator+(Int j, iterator k) { return k + j; }
+#else
+ inline iterator &operator+=(qsizetype j) { i += j; return *this; }
+ inline iterator &operator-=(qsizetype j) { i -= j; return *this; }
+ inline iterator operator+(qsizetype j) const { return iterator(i + j); }
+ inline iterator operator-(qsizetype j) const { return iterator(i - j); }
+ friend inline iterator operator+(qsizetype j, iterator k) { return k + j; }
+#endif
};
class const_iterator {
+ friend class QList<T>;
+ friend class iterator;
const T *i = nullptr;
+#ifdef QT_STRICT_QLIST_ITERATORS
+ inline constexpr explicit const_iterator(const T *n) : i(n) {}
+#endif
+
public:
using difference_type = qsizetype;
using value_type = T;
- // libstdc++ shipped with gcc < 11 does not have a fix for defect LWG 3346
-#if __cplusplus >= 202002L && (!defined(_GLIBCXX_RELEASE) || _GLIBCXX_RELEASE >= 11)
- using iterator_category = std::contiguous_iterator_tag;
+#ifdef QT_COMPILER_HAS_LWG3346
+ using iterator_concept = std::contiguous_iterator_tag;
using element_type = const value_type;
-#else
- using iterator_category = std::random_access_iterator_tag;
#endif
+ using iterator_category = std::random_access_iterator_tag;
using pointer = const T *;
using reference = const T &;
inline constexpr const_iterator() = default;
- inline const_iterator(const T *n) : i(n) {}
- inline constexpr const_iterator(iterator o): i(o) {}
+#ifndef QT_STRICT_QLIST_ITERATORS
+ inline constexpr explicit const_iterator(const T *n) : i(n) {}
+#endif
+ inline constexpr const_iterator(iterator o): i(o.i) {}
inline const T &operator*() const { return *i; }
inline const T *operator->() const { return i; }
inline const T &operator[](qsizetype j) const { return *(i + j); }
@@ -198,21 +209,42 @@ public:
inline constexpr bool operator<=(const_iterator other) const { return i <= other.i; }
inline constexpr bool operator>(const_iterator other) const { return i > other.i; }
inline constexpr bool operator>=(const_iterator other) const { return i >= other.i; }
- inline constexpr bool operator==(iterator o) const { return i == const_iterator(o).i; }
- inline constexpr bool operator!=(iterator o) const { return i != const_iterator(o).i; }
+ inline constexpr bool operator==(iterator o) const { return i == o.i; }
+ inline constexpr bool operator!=(iterator o) const { return i != o.i; }
+ inline constexpr bool operator<(iterator other) const { return i < other.i; }
+ inline constexpr bool operator<=(iterator other) const { return i <= other.i; }
+ inline constexpr bool operator>(iterator other) const { return i > other.i; }
+ inline constexpr bool operator>=(iterator other) const { return i >= other.i; }
inline constexpr bool operator==(pointer p) const { return i == p; }
inline constexpr bool operator!=(pointer p) const { return i != p; }
inline const_iterator &operator++() { ++i; return *this; }
- inline const_iterator operator++(int) { const T *n = i; ++i; return n; }
- inline const_iterator &operator--() { i--; return *this; }
- inline const_iterator operator--(int) { const T *n = i; i--; return n; }
- inline const_iterator &operator+=(qsizetype j) { i+=j; return *this; }
- inline const_iterator &operator-=(qsizetype j) { i-=j; return *this; }
- inline const_iterator operator+(qsizetype j) const { return const_iterator(i+j); }
- inline const_iterator operator-(qsizetype j) const { return const_iterator(i-j); }
- friend inline const_iterator operator+(qsizetype j, const_iterator k) { return k + j; }
+ inline const_iterator operator++(int) { auto copy = *this; ++*this; return copy; }
+ inline const_iterator &operator--() { --i; return *this; }
+ inline const_iterator operator--(int) { auto copy = *this; --*this; return copy; }
inline qsizetype operator-(const_iterator j) const { return i - j.i; }
+#if QT_DEPRECATED_SINCE(6, 3) && !defined(QT_STRICT_QLIST_ITERATORS)
+ QT_DEPRECATED_VERSION_X_6_3("Use operator* or operator-> rather than relying on "
+ "the implicit conversion between a QList/QVector::const_iterator "
+ "and a raw pointer")
inline operator const T*() const { return i; }
+
+ template <typename Int> std::enable_if_t<std::is_integral_v<Int>, const_iterator>
+ &operator+=(Int j) { i+=j; return *this; }
+ template <typename Int> std::enable_if_t<std::is_integral_v<Int>, const_iterator>
+ &operator-=(Int j) { i-=j; return *this; }
+ template <typename Int> std::enable_if_t<std::is_integral_v<Int>, const_iterator>
+ operator+(Int j) const { return const_iterator(i+j); }
+ template <typename Int> std::enable_if_t<std::is_integral_v<Int>, const_iterator>
+ operator-(Int j) const { return const_iterator(i-j); }
+ template <typename Int> friend std::enable_if_t<std::is_integral_v<Int>, const_iterator>
+ operator+(Int j, const_iterator k) { return k + j; }
+#else
+ inline const_iterator &operator+=(qsizetype j) { i += j; return *this; }
+ inline const_iterator &operator-=(qsizetype j) { i -= j; return *this; }
+ inline const_iterator operator+(qsizetype j) const { return const_iterator(i + j); }
+ inline const_iterator operator-(qsizetype j) const { return const_iterator(i - j); }
+ friend inline const_iterator operator+(qsizetype j, const_iterator k) { return k + j; }
+#endif
};
using Iterator = iterator;
using ConstIterator = const_iterator;
@@ -224,7 +256,15 @@ private:
bool isValidIterator(const_iterator i) const
{
const std::less<const T*> less = {};
- return !less(d->end(), i) && !less(i, d->begin());
+ return !less(d->end(), i.i) && !less(i.i, d->begin());
+ }
+
+ void verify([[maybe_unused]] qsizetype pos = 0, [[maybe_unused]] qsizetype n = 1) const
+ {
+ Q_ASSERT(pos >= 0);
+ Q_ASSERT(pos <= size());
+ Q_ASSERT(n >= 0);
+ Q_ASSERT(n <= size() - pos);
}
public:
QList(DataPointer dd) noexcept
@@ -235,20 +275,20 @@ public:
public:
QList() = default;
explicit QList(qsizetype size)
- : d(Data::allocate(size))
+ : d(size)
{
if (size)
d->appendInitialize(size);
}
QList(qsizetype size, parameter_type t)
- : d(Data::allocate(size))
+ : d(size)
{
if (size)
d->copyAppend(size, t);
}
inline QList(std::initializer_list<T> args)
- : d(Data::allocate(args.size()))
+ : d(qsizetype(args.size()))
{
if (args.size())
d->copyAppend(args.begin(), args.end());
@@ -256,23 +296,23 @@ public:
QList<T> &operator=(std::initializer_list<T> args)
{
- d = DataPointer(Data::allocate(args.size()));
- if (args.size())
- d->copyAppend(args.begin(), args.end());
- return *this;
+ return assign(args);
}
- template <typename InputIterator, QtPrivate::IfIsInputIterator<InputIterator> = true>
+
+ template <typename InputIterator, if_input_iterator<InputIterator> = true>
QList(InputIterator i1, InputIterator i2)
{
- if constexpr (!std::is_convertible_v<typename std::iterator_traits<Iterator>::iterator_category, std::forward_iterator_tag>) {
+ if constexpr (!std::is_convertible_v<typename std::iterator_traits<InputIterator>::iterator_category, std::forward_iterator_tag>) {
std::copy(i1, i2, std::back_inserter(*this));
} else {
const auto distance = std::distance(i1, i2);
if (distance) {
- d = DataPointer(Data::allocate(distance));
+ d = DataPointer(qsizetype(distance));
+ // appendIteratorRange can deal with contiguous iterators on its own,
+ // this is an optimization for C++17 code.
if constexpr (std::is_same_v<std::decay_t<InputIterator>, iterator> ||
std::is_same_v<std::decay_t<InputIterator>, const_iterator>) {
- d->copyAppend(i1, i2);
+ d->copyAppend(i1.i, i2.i);
} else {
d->appendIteratorRange(i1, i2);
}
@@ -285,10 +325,18 @@ public:
inline explicit QList(const String &str)
{ append(str); }
+ QList(qsizetype size, Qt::Initialization)
+ : d(size)
+ {
+ if (size)
+ d->appendUninitialized(size);
+ }
+
// compiler-generated special member functions are fine!
- void swap(QList<T> &other) noexcept { qSwap(d, other.d); }
+ void swap(QList &other) noexcept { d.swap(other.d); }
+#ifndef Q_QDOC
template <typename U = T>
QTypeTraits::compare_eq_result_container<QList, U> operator==(const QList &other) const
{
@@ -298,7 +346,7 @@ public:
return true;
// do element-by-element comparison
- return d->compare(begin(), other.begin(), size());
+ return d->compare(data(), other.data(), size());
}
template <typename U = T>
QTypeTraits::compare_eq_result_container<QList, U> operator!=(const QList &other) const
@@ -337,6 +385,14 @@ public:
{
return !(*this < other);
}
+#else
+ bool operator==(const QList &other) const;
+ bool operator!=(const QList &other) const;
+ bool operator<(const QList &other) const;
+ bool operator>(const QList &other) const;
+ bool operator<=(const QList &other) const;
+ bool operator>=(const QList &other) const;
+#endif // Q_QDOC
qsizetype size() const noexcept { return d->size; }
qsizetype count() const noexcept { return size(); }
@@ -356,6 +412,12 @@ public:
if (size > this->size())
d->copyAppend(size - this->size(), c);
}
+ void resizeForOverwrite(qsizetype size)
+ {
+ resize_internal(size);
+ if (size > this->size())
+ d->appendUninitialized(size);
+ }
inline qsizetype capacity() const { return qsizetype(d->constAllocatedCapacity()); }
void reserve(qsizetype size);
@@ -374,7 +436,7 @@ public:
return;
if (d->needsDetach()) {
// must allocate memory
- DataPointer detached(Data::allocate(d.allocatedCapacity()));
+ DataPointer detached(d.allocatedCapacity());
d.swap(detached);
} else {
d->truncate(0);
@@ -389,7 +451,7 @@ public:
reference operator[](qsizetype i)
{
Q_ASSERT_X(size_t(i) < size_t(d->size), "QList::operator[]", "index out of range");
- detach();
+ // don't detach() here, we detach in data below:
return data()[i];
}
const_reference operator[](qsizetype i) const noexcept { return at(i); }
@@ -451,6 +513,19 @@ public:
}
}
+ QList &assign(qsizetype n, parameter_type t)
+ {
+ Q_ASSERT(n >= 0);
+ return fill(t, n);
+ }
+
+ template <typename InputIterator, if_input_iterator<InputIterator> = true>
+ QList &assign(InputIterator first, InputIterator last)
+ { d.assign(first, last); return *this; }
+
+ QList &assign(std::initializer_list<T> l)
+ { return assign(l.begin(), l.end()); }
+
template <typename ...Args>
iterator emplace(const_iterator before, Args&&... args)
{
@@ -509,7 +584,7 @@ public:
template <typename AT = T>
qsizetype count(const AT &t) const noexcept
{
- return qsizetype(std::count(&*cbegin(), &*cend(), t));
+ return qsizetype(std::count(data(), data() + size(), t));
}
void removeAt(qsizetype i) { remove(i); }
@@ -547,15 +622,15 @@ public:
}
// STL-style
- iterator begin() { detach(); return d->begin(); }
- iterator end() { detach(); return d->end(); }
-
- const_iterator begin() const noexcept { return d->constBegin(); }
- const_iterator end() const noexcept { return d->constEnd(); }
- const_iterator cbegin() const noexcept { return d->constBegin(); }
- const_iterator cend() const noexcept { return d->constEnd(); }
- const_iterator constBegin() const noexcept { return d->constBegin(); }
- const_iterator constEnd() const noexcept { return d->constEnd(); }
+ iterator begin() { detach(); return iterator(d->begin()); }
+ iterator end() { detach(); return iterator(d->end()); }
+
+ const_iterator begin() const noexcept { return const_iterator(d->constBegin()); }
+ const_iterator end() const noexcept { return const_iterator(d->constEnd()); }
+ const_iterator cbegin() const noexcept { return const_iterator(d->constBegin()); }
+ const_iterator cend() const noexcept { return const_iterator(d->constEnd()); }
+ const_iterator constBegin() const noexcept { return const_iterator(d->constBegin()); }
+ const_iterator constEnd() const noexcept { return const_iterator(d->constEnd()); }
reverse_iterator rbegin() { return reverse_iterator(end()); }
reverse_iterator rend() { return reverse_iterator(begin()); }
const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(end()); }
@@ -578,27 +653,13 @@ public:
QList<T> mid(qsizetype pos, qsizetype len = -1) const;
QList<T> first(qsizetype n) const
- {
- Q_ASSERT(size_t(n) <= size_t(size()));
- return QList<T>(begin(), begin() + n);
- }
+ { verify(0, n); return QList<T>(begin(), begin() + n); }
QList<T> last(qsizetype n) const
- {
- Q_ASSERT(size_t(n) <= size_t(size()));
- return QList<T>(end() - n, end());
- }
+ { verify(0, n); return QList<T>(end() - n, end()); }
QList<T> sliced(qsizetype pos) const
- {
- Q_ASSERT(size_t(pos) <= size_t(size()));
- return QList<T>(begin() + pos, end());
- }
+ { verify(pos, 0); return QList<T>(begin() + pos, end()); }
QList<T> sliced(qsizetype pos, qsizetype n) const
- {
- Q_ASSERT(size_t(pos) <= size_t(size()));
- Q_ASSERT(n >= 0);
- Q_ASSERT(pos + n <= size());
- return QList<T>(begin() + pos, begin() + pos + n);
- }
+ { verify(pos, n); return QList<T>(begin() + pos, begin() + pos + n); }
T value(qsizetype i) const { return value(i, T()); }
T value(qsizetype i, parameter_type defaultValue) const;
@@ -628,14 +689,22 @@ public:
inline reference back() { return last(); }
inline const_reference back() const noexcept { return last(); }
void shrink_to_fit() { squeeze(); }
+ static qsizetype max_size() noexcept
+ {
+ return Data::max_size();
+ }
// comfort
QList<T> &operator+=(const QList<T> &l) { append(l); return *this; }
QList<T> &operator+=(QList<T> &&l) { append(std::move(l)); return *this; }
- inline QList<T> operator+(const QList<T> &l) const
+ inline QList<T> operator+(const QList<T> &l) const &
{ QList n = *this; n += l; return n; }
- inline QList<T> operator+(QList<T> &&l) const
+ QList<T> operator+(const QList<T> &l) &&
+ { return std::move(*this += l); }
+ inline QList<T> operator+(QList<T> &&l) const &
{ QList n = *this; n += std::move(l); return n; }
+ QList<T> operator+(QList<T> &&l) &&
+ { return std::move(*this += std::move(l)); }
inline QList<T> &operator+=(parameter_type t)
{ append(t); return *this; }
inline QList<T> &operator<< (parameter_type t)
@@ -663,12 +732,10 @@ public:
}
};
-#if defined(__cpp_deduction_guides) && __cpp_deduction_guides >= 201606
template <typename InputIterator,
typename ValueType = typename std::iterator_traits<InputIterator>::value_type,
QtPrivate::IfIsInputIterator<InputIterator> = true>
QList(InputIterator, InputIterator) -> QList<ValueType>;
-#endif
template <typename T>
inline void QList<T>::resize_internal(qsizetype newSize)
@@ -696,8 +763,8 @@ void QList<T>::reserve(qsizetype asize)
}
}
- DataPointer detached(Data::allocate(qMax(asize, size())));
- detached->copyAppend(constBegin(), constEnd());
+ DataPointer detached(qMax(asize, size()));
+ detached->copyAppend(d->begin(), d->end());
if (detached.d_ptr())
detached->setFlag(Data::CapacityReserved);
d.swap(detached);
@@ -710,10 +777,10 @@ inline void QList<T>::squeeze()
return;
if (d->needsDetach() || size() < capacity()) {
// must allocate memory
- DataPointer detached(Data::allocate(size()));
+ DataPointer detached(size());
if (size()) {
if (d.needsDetach())
- detached->copyAppend(constBegin(), constEnd());
+ detached->copyAppend(d.data(), d.data() + d.size);
else
detached->moveAppend(d.data(), d.data() + d.size);
}
@@ -762,7 +829,7 @@ inline T QList<T>::value(qsizetype i, parameter_type defaultValue) const
template <typename T>
inline void QList<T>::append(const_iterator i1, const_iterator i2)
{
- d->growAppend(i1, i2);
+ d->growAppend(i1.i, i2.i);
}
template <typename T>
@@ -777,7 +844,7 @@ inline void QList<T>::append(QList<T> &&other)
// due to precondition &other != this, we can unconditionally modify 'this'
d.detachAndGrow(QArrayData::GrowsAtEnd, other.size(), nullptr, nullptr);
Q_ASSERT(d.freeSpaceAtEnd() >= other.size());
- d->moveAppend(other.begin(), other.end());
+ d->moveAppend(other.d->begin(), other.d->end());
}
template<typename T>
@@ -797,7 +864,7 @@ QList<T>::insert(qsizetype i, qsizetype n, parameter_type t)
Q_ASSERT_X(n >= 0, "QList::insert", "invalid count");
if (Q_LIKELY(n))
d->insert(i, n, t);
- return d.begin() + i;
+ return begin() + i;
}
template <typename T>
@@ -807,7 +874,7 @@ QList<T>::emplace(qsizetype i, Args&&... args)
{
Q_ASSERT_X(i >= 0 && i <= d->size, "QList<T>::insert", "index out of range");
d->emplace(i, std::forward<Args>(args)...);
- return d.begin() + i;
+ return begin() + i;
}
template<typename T>
@@ -815,7 +882,7 @@ template<typename... Args>
inline typename QList<T>::reference QList<T>::emplaceBack(Args &&... args)
{
d->emplace(d->size, std::forward<Args>(args)...);
- return *(d.end() - 1);
+ return *(end() - 1);
}
template <typename T>
@@ -829,7 +896,7 @@ typename QList<T>::iterator QList<T>::erase(const_iterator abegin, const_iterato
qsizetype n = std::distance(abegin, aend);
remove(i, n);
- return d.begin() + i;
+ return begin() + i;
}
template <typename T>
@@ -839,7 +906,7 @@ inline QList<T> &QList<T>::fill(parameter_type t, qsizetype newSize)
newSize = size();
if (d->needsDetach() || newSize > capacity()) {
// must allocate memory
- DataPointer detached(Data::allocate(d->detachCapacity(newSize)));
+ DataPointer detached(d->detachCapacity(newSize));
detached->copyAppend(newSize, t);
d.swap(detached);
} else {
@@ -921,8 +988,8 @@ inline QList<T> QList<T>::mid(qsizetype pos, qsizetype len) const
}
// Allocate memory
- DataPointer copied(Data::allocate(l));
- copied->copyAppend(constBegin() + p, constBegin() + p + l);
+ DataPointer copied(l);
+ copied->copyAppend(data() + p, data() + p + l);
return copied;
}