diff --git a/src/corelib/tools/qarraydata.h b/src/corelib/tools/qarraydata.h index b66a5add04..c1f9656707 100644 --- a/src/corelib/tools/qarraydata.h +++ b/src/corelib/tools/qarraydata.h @@ -133,8 +133,72 @@ template struct QTypedArrayData : QArrayData { - typedef T* iterator; - typedef const T* const_iterator; + 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 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 bool operator==(const_iterator o) const { return i == o.i; } + inline bool operator!=(const_iterator o) const { return i != o.i; } + inline bool operator<(const_iterator other) const { return i < other.i; } + inline bool operator<=(const_iterator other) const { return i <= other.i; } + inline bool operator>(const_iterator other) const { return i > other.i; } + inline bool operator>=(const_iterator other) const { return i >= other.i; } + 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; } + }; class AlignmentDummy { QArrayData header; T data; }; diff --git a/src/tools/qlalr/compress.cpp b/src/tools/qlalr/compress.cpp index eb4ccdc783..ae0fbaca9d 100644 --- a/src/tools/qlalr/compress.cpp +++ b/src/tools/qlalr/compress.cpp @@ -186,7 +186,7 @@ void Compress::operator () (int *table, int row_count, int column_count) if (pos == info.begin ()) { // try to find a perfect match - QList::iterator pm = std::search(pos, info.end(), row.beginNonZeros(), + QList::iterator pm = std::search(&*pos, &*info.end(), row.beginNonZeros(), row.endNonZeros(), _PerfectMatch()); if (pm != info.end ()) @@ -196,7 +196,7 @@ void Compress::operator () (int *table, int row_count, int column_count) } } - pos = std::search (pos, info.end (), row.beginNonZeros (), row.endNonZeros (), _Fit ()); + pos = std::search (&*pos, &*info.end (), row.beginNonZeros (), row.endNonZeros (), _Fit ()); if (pos == info.end ()) break;