summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qlist.h
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-11-13 12:04:20 +0100
committerLars Knoll <lars.knoll@qt.io>2020-11-17 11:47:53 +0100
commit7fc302520b905fc40cc0fa439d3a2e9dbff3e5a6 (patch)
tree8b8113c86e6dc9053f14c5e1e59481eef30c8897 /src/corelib/tools/qlist.h
parentcadfed83acd392bb9dde6dded241aeefabc235ec (diff)
Move the iterator from QTypedArrayData to QList
The low level implementation does not use it at all, so there's no point having the iterator in QTypedArrayData. Having it in QList removes and indirection and will lead to clearer error messages. Change-Id: I4af270c3cdb39620e5e52e835eb8fe1aa659e038 Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Diffstat (limited to 'src/corelib/tools/qlist.h')
-rw-r--r--src/corelib/tools/qlist.h90
1 files changed, 78 insertions, 12 deletions
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h
index 85d3b30432..517ba10326 100644
--- a/src/corelib/tools/qlist.h
+++ b/src/corelib/tools/qlist.h
@@ -121,17 +121,6 @@ public:
using size_type = qsizetype;
using difference_type = qptrdiff;
#ifndef Q_QDOC
- using iterator = typename Data::iterator;
- using const_iterator = typename Data::const_iterator;
-#else // simplified aliases for QDoc
- using iterator = T *;
- using const_iterator = const T *;
-#endif
- using Iterator = iterator;
- using ConstIterator = const_iterator;
- using reverse_iterator = std::reverse_iterator<iterator>;
- using const_reverse_iterator = std::reverse_iterator<const_iterator>;
-#ifndef Q_QDOC
using parameter_type = typename DataPointer::parameter_type;
using rvalue_ref = typename std::conditional<DataPointer::pass_parameter_by_value, DisableRValueRefs, T &&>::type;
#else // simplified aliases for QDoc
@@ -139,6 +128,83 @@ public:
using rvalue_ref = T &&;
#endif
+ class iterator {
+ T *i = nullptr;
+ public:
+ typedef std::random_access_iterator_tag iterator_category;
+ typedef qsizetype difference_type;
+ typedef T value_type;
+ typedef T *pointer;
+ typedef T &reference;
+
+ inline constexpr iterator() = default;
+ inline iterator(T *n) : i(n) {}
+ inline T &operator*() const { return *i; }
+ inline T *operator->() const { return i; }
+ inline T &operator[](qsizetype j) const { return *(i + j); }
+ 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 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 qsizetype operator-(iterator j) const { return i - j.i; }
+ inline operator T*() const { return i; }
+ };
+
+ class const_iterator {
+ const T *i = nullptr;
+ public:
+ typedef std::random_access_iterator_tag iterator_category;
+ typedef qsizetype difference_type;
+ typedef T value_type;
+ typedef const T *pointer;
+ typedef const T &reference;
+
+ inline constexpr const_iterator() = default;
+ inline const_iterator(const T *n) : i(n) {}
+ inline constexpr const_iterator(iterator o): i(o) {}
+ inline const T &operator*() const { return *i; }
+ inline const T *operator->() const { return i; }
+ inline const T &operator[](qsizetype j) const { return *(i + j); }
+ 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==(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==(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 qsizetype operator-(const_iterator j) const { return i - j.i; }
+ inline operator const T*() const { return i; }
+ };
+ using Iterator = iterator;
+ using ConstIterator = const_iterator;
+ using reverse_iterator = std::reverse_iterator<iterator>;
+ using const_reverse_iterator = std::reverse_iterator<const_iterator>;
+
private:
void resize_internal(qsizetype i);
bool isValidIterator(const_iterator i) const
@@ -758,7 +824,7 @@ typename QList<T>::iterator QList<T>::erase(const_iterator abegin, const_iterato
Q_ASSERT_X(isValidIterator(aend), "QList::erase", "The specified iterator argument 'aend' is invalid");
Q_ASSERT(aend >= abegin);
- qsizetype i = std::distance(d.constBegin(), abegin);
+ qsizetype i = std::distance(constBegin(), abegin);
qsizetype n = std::distance(abegin, aend);
remove(i, n);