diff --git a/src/corelib/tools/qarraydata.h b/src/corelib/tools/qarraydata.h index cbd9445d18..c76ff3d9f0 100644 --- a/src/corelib/tools/qarraydata.h +++ b/src/corelib/tools/qarraydata.h @@ -132,79 +132,6 @@ template struct QTypedArrayData : QArrayData { - 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; } - }; - struct AlignmentDummy { QArrayData header; T data; }; [[nodiscard]] static QPair allocate(qsizetype capacity, AllocationOption option = QArrayData::KeepSize) diff --git a/src/corelib/tools/qarraydataops.h b/src/corelib/tools/qarraydataops.h index b157e2d733..c1ae93dc10 100644 --- a/src/corelib/tools/qarraydataops.h +++ b/src/corelib/tools/qarraydataops.h @@ -635,7 +635,7 @@ public: { Q_ASSERT(this->isMutable()); Q_ASSERT(this->size); - (--this->end())->~T(); + (this->end() - 1)->~T(); --this->size; } @@ -883,8 +883,6 @@ struct QCommonArrayOps : QArrayOpsSelector::Type using Data = QTypedArrayData; using DataPointer = QArrayDataPointer; using parameter_type = typename Base::parameter_type; - using iterator = typename Base::iterator; - using const_iterator = typename Base::const_iterator; protected: using Self = QCommonArrayOps; diff --git a/src/corelib/tools/qarraydatapointer.h b/src/corelib/tools/qarraydatapointer.h index 763a5f7927..aa94819b35 100644 --- a/src/corelib/tools/qarraydatapointer.h +++ b/src/corelib/tools/qarraydatapointer.h @@ -53,8 +53,6 @@ private: typedef QArrayDataOps DataOps; public: - typedef typename Data::iterator iterator; - typedef typename Data::const_iterator const_iterator; enum { pass_parameter_by_value = std::is_arithmetic::value || std::is_pointer::value || std::is_enum::value @@ -142,12 +140,12 @@ public: T *data() noexcept { return ptr; } const T *data() const noexcept { return ptr; } - iterator begin(iterator = iterator()) noexcept { return data(); } - iterator end(iterator = iterator()) noexcept { return data() + size; } - const_iterator begin(const_iterator = const_iterator()) const noexcept { return data(); } - const_iterator end(const_iterator = const_iterator()) const noexcept { return data() + size; } - const_iterator constBegin(const_iterator = const_iterator()) const noexcept { return data(); } - const_iterator constEnd(const_iterator = const_iterator()) const noexcept { return data() + size; } + T *begin() noexcept { return data(); } + T *end() noexcept { return data() + size; } + const T *begin() const noexcept { return data(); } + const T *end() const noexcept { return data() + size; } + const T *constBegin() const noexcept { return data(); } + const T *constEnd() const noexcept { return data() + size; } void swap(QArrayDataPointer &other) noexcept { 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 @@ -120,17 +120,6 @@ public: using const_reference = const T &; 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; - using const_reverse_iterator = std::reverse_iterator; #ifndef Q_QDOC using parameter_type = typename DataPointer::parameter_type; using rvalue_ref = typename std::conditional::type; @@ -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; + using const_reverse_iterator = std::reverse_iterator; + private: void resize_internal(qsizetype i); bool isValidIterator(const_iterator i) const @@ -758,7 +824,7 @@ typename QList::iterator QList::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); diff --git a/tests/auto/corelib/tools/qarraydata/simplevector.h b/tests/auto/corelib/tools/qarraydata/simplevector.h index 74227dd8d0..747af3d422 100644 --- a/tests/auto/corelib/tools/qarraydata/simplevector.h +++ b/tests/auto/corelib/tools/qarraydata/simplevector.h @@ -44,8 +44,8 @@ private: public: typedef T value_type; - typedef typename Data::iterator iterator; - typedef typename Data::const_iterator const_iterator; + typedef T *iterator; + typedef const T *const_iterator; SimpleVector() {