implement non-member operator+ for iterators
all of these iterator classes already have a member operator+, which allows iter+int. This commits addes non-member operator+, which allows int+iter, and forwards to the member QList and QArrayData iterators now satisfy RandomAccessIterator concept Change-Id: I25c1dd8cea299e735d5a5e288dbe23dc1d7a1933 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
ada1b61991
commit
2869bf9f1e
@ -627,6 +627,7 @@ public:
|
||||
const_iterator &operator-=(int j);
|
||||
const_iterator operator+(int j) const;
|
||||
const_iterator operator-(int j) const;
|
||||
friend inline const_iterator operator+(int j, const_iterator k) { return k + j; }
|
||||
};
|
||||
|
||||
friend struct const_iterator;
|
||||
@ -684,6 +685,7 @@ public:
|
||||
const_iterator &operator-=(int j);
|
||||
const_iterator operator+(int j) const;
|
||||
const_iterator operator-(int j) const;
|
||||
friend inline const_iterator operator+(int j, const_iterator k) { return k + j; }
|
||||
};
|
||||
|
||||
friend struct const_iterator;
|
||||
|
@ -136,6 +136,7 @@ public:
|
||||
inline const_iterator operator-(int j) const { return const_iterator(future, index - j); }
|
||||
inline const_iterator &operator+=(int j) { index += j; return *this; }
|
||||
inline const_iterator &operator-=(int j) { index -= j; return *this; }
|
||||
friend inline const_iterator operator+(int j, const_iterator k) { return k + j; }
|
||||
private:
|
||||
QFuture const * future;
|
||||
int index;
|
||||
|
@ -159,6 +159,7 @@ struct QTypedArrayData
|
||||
inline iterator &operator-=(int j) { i-=j; return *this; }
|
||||
inline iterator operator+(int j) const { return iterator(i+j); }
|
||||
inline iterator operator-(int j) const { return iterator(i-j); }
|
||||
friend inline iterator operator+(int j, iterator k) { return k + j; }
|
||||
inline int operator-(iterator j) const { return i - j.i; }
|
||||
inline operator T*() const { return i; }
|
||||
};
|
||||
@ -194,6 +195,7 @@ struct QTypedArrayData
|
||||
inline const_iterator &operator-=(int j) { i-=j; return *this; }
|
||||
inline const_iterator operator+(int j) const { return const_iterator(i+j); }
|
||||
inline const_iterator operator-(int j) const { return const_iterator(i-j); }
|
||||
friend inline const_iterator operator+(int j, const_iterator k) { return k + j; }
|
||||
inline int operator-(const_iterator j) const { return i - j.i; }
|
||||
inline operator const T*() const { return i; }
|
||||
};
|
||||
|
@ -348,6 +348,7 @@ public:
|
||||
inline iterator operator-(int j) const { return operator+(-j); }
|
||||
inline iterator &operator+=(int j) { return *this = *this + j; }
|
||||
inline iterator &operator-=(int j) { return *this = *this - j; }
|
||||
friend inline iterator operator+(int j, iterator k) { return k + j; }
|
||||
|
||||
#ifndef QT_STRICT_ITERATORS
|
||||
public:
|
||||
@ -413,6 +414,7 @@ public:
|
||||
inline const_iterator operator-(int j) const { return operator+(-j); }
|
||||
inline const_iterator &operator+=(int j) { return *this = *this + j; }
|
||||
inline const_iterator &operator-=(int j) { return *this = *this - j; }
|
||||
friend inline const_iterator operator+(int j, const_iterator k) { return k + j; }
|
||||
|
||||
// ### Qt 5: not sure this is necessary anymore
|
||||
#ifdef QT_STRICT_ITERATORS
|
||||
|
@ -159,6 +159,7 @@ public:
|
||||
inline iterator operator-(int j) const { return operator+(-j); }
|
||||
inline iterator &operator+=(int j) { return *this = *this + j; }
|
||||
inline iterator &operator-=(int j) { return *this = *this - j; }
|
||||
friend inline iterator operator+(int j, iterator k) { return k + j; }
|
||||
};
|
||||
friend class iterator;
|
||||
|
||||
@ -193,6 +194,7 @@ public:
|
||||
inline const_iterator operator-(int j) const { return operator+(-j); }
|
||||
inline const_iterator &operator+=(int j) { return *this = *this + j; }
|
||||
inline const_iterator &operator-=(int j) { return *this = *this - j; }
|
||||
friend inline const_iterator operator+(int j, const_iterator k) { return k + j; }
|
||||
};
|
||||
friend class const_iterator;
|
||||
|
||||
|
@ -269,6 +269,7 @@ public:
|
||||
inline iterator &operator-=(difference_type j) { i-=j; return *this; }
|
||||
inline iterator operator+(difference_type j) const { return iterator(i+j); }
|
||||
inline iterator operator-(difference_type j) const { return iterator(i-j); }
|
||||
friend inline iterator operator+(difference_type j, iterator k) { return k + j; }
|
||||
inline int operator-(iterator j) const { return int(i - j.i); }
|
||||
};
|
||||
friend class iterator;
|
||||
@ -312,6 +313,7 @@ public:
|
||||
inline const_iterator &operator-=(difference_type j) { i-=j; return *this; }
|
||||
inline const_iterator operator+(difference_type j) const { return const_iterator(i+j); }
|
||||
inline const_iterator operator-(difference_type j) const { return const_iterator(i-j); }
|
||||
friend inline const_iterator operator+(difference_type j, const_iterator k) { return k + j; }
|
||||
inline int operator-(const_iterator j) const { return int(i - j.i); }
|
||||
};
|
||||
friend class const_iterator;
|
||||
|
@ -449,6 +449,7 @@ public:
|
||||
inline iterator operator-(int j) const { return operator+(-j); }
|
||||
inline iterator &operator+=(int j) { return *this = *this + j; }
|
||||
inline iterator &operator-=(int j) { return *this = *this - j; }
|
||||
friend inline iterator operator+(int j, iterator k) { return k + j; }
|
||||
|
||||
#ifndef QT_STRICT_ITERATORS
|
||||
public:
|
||||
@ -512,6 +513,7 @@ public:
|
||||
inline const_iterator operator-(int j) const { return operator+(-j); }
|
||||
inline const_iterator &operator+=(int j) { return *this = *this + j; }
|
||||
inline const_iterator &operator-=(int j) { return *this = *this - j; }
|
||||
friend inline const_iterator operator+(int j, const_iterator k) { return k + j; }
|
||||
|
||||
#ifdef QT_STRICT_ITERATORS
|
||||
private:
|
||||
|
@ -131,6 +131,7 @@ public:
|
||||
inline iterator operator--(int) { iterator r = *this; --i; return r; }
|
||||
inline iterator operator+(int j) const { return i + j; }
|
||||
inline iterator operator-(int j) const { return i - j; }
|
||||
friend inline iterator operator+(int j, iterator k) { return k + j; }
|
||||
inline iterator &operator+=(int j) { i += j; return *this; }
|
||||
inline iterator &operator-=(int j) { i -= j; return *this; }
|
||||
};
|
||||
@ -165,6 +166,7 @@ public:
|
||||
inline const_iterator operator--(int) { const_iterator r = *this; --i; return r; }
|
||||
inline const_iterator operator+(int j) const { return i + j; }
|
||||
inline const_iterator operator-(int j) const { return i - j; }
|
||||
friend inline const_iterator operator+(int j, const_iterator k) { return k + j; }
|
||||
inline const_iterator &operator+=(int j) { i += j; return *this; }
|
||||
inline const_iterator &operator-=(int j) { i -= j; return *this; }
|
||||
};
|
||||
|
@ -1021,6 +1021,8 @@ void tst_QFuture::iterators()
|
||||
QCOMPARE(i2, c2);
|
||||
QCOMPARE(c2, i2);
|
||||
QCOMPARE(c2, c2);
|
||||
QCOMPARE(1 + i1, i1 + 1);
|
||||
QCOMPARE(1 + c1, c1 + 1);
|
||||
|
||||
QVERIFY(i1 != i2);
|
||||
QVERIFY(i1 != c2);
|
||||
@ -1070,6 +1072,8 @@ void tst_QFuture::iterators()
|
||||
QCOMPARE(i2, c2);
|
||||
QCOMPARE(c2, i2);
|
||||
QCOMPARE(c2, c2);
|
||||
QCOMPARE(1 + i1, i1 + 1);
|
||||
QCOMPARE(1 + c1, c1 + 1);
|
||||
|
||||
QVERIFY(i1 != i2);
|
||||
QVERIFY(i1 != c2);
|
||||
|
@ -2620,6 +2620,8 @@ void testLinkedListLikeStlIterators()
|
||||
QVERIFY(i2 == c2);
|
||||
QVERIFY(c2 == i2);
|
||||
QVERIFY(c2 == c2);
|
||||
QVERIFY(1 + i1 == i1 + 1);
|
||||
QVERIFY(1 + c1 == c1 + 1);
|
||||
|
||||
QVERIFY(i1 != i2);
|
||||
QVERIFY(i1 != c2);
|
||||
@ -2731,6 +2733,8 @@ void testMapLikeStlIterators()
|
||||
QVERIFY(i2 == c2);
|
||||
QVERIFY(c2 == i2);
|
||||
QVERIFY(c2 == c2);
|
||||
QVERIFY(1 + i1 == i1 + 1);
|
||||
QVERIFY(1 + c1 == c1 + 1);
|
||||
|
||||
QVERIFY(i1 != i2);
|
||||
QVERIFY(i1 != c2);
|
||||
|
Loading…
Reference in New Issue
Block a user