diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2015-03-31 00:14:24 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2015-10-13 18:07:20 +0000 |
commit | 967e4f258cd39991fd2d0ac3753544900d51fbc2 (patch) | |
tree | 6a2ef53300750c0efcf8ce16332522fe2bbed8c3 /tests/auto/corelib/tools | |
parent | 0df5d079290b4c3b13e58e9397fabdc1dfdba96b (diff) |
QLinkedList/QSet: add {const_,}reverse_iterator, {c,}r{begin,end}()
Now all Qt sequential containers consistently provide reverse iterators.
The associative ones, by way of not returning std::pair from op*, can't
just use std::reverse_iterator. They would miss .key() and .value() methods.
So that has to wait for 5.7.
The reverse versions of the new key_iterators can also just use
std::reverse_iterator, but I'm afraid that after bikeshedding over
keyRBegin() vs. rKeyBegin() vs. reverseKeyBegin() vs. rkbegin()
vs. krbegin() (<-- of course, what else?), it would anyway be too
late for 5.6, so defer, too.
[ChangeLog][QtCore][QLinkedList/QSet] Added rbegin(), crbegin(), rend(), crend(),
and reverse_iterator and const_reverse_iterator typedefs.
Task-number: QTBUG-25919
Change-Id: I58316fffade469e9a42c61d7aa1455ae3443fd94
Reviewed-by: Sérgio Martins <sergio.martins@kdab.com>
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'tests/auto/corelib/tools')
-rw-r--r-- | tests/auto/corelib/tools/qlinkedlist/tst_qlinkedlist.cpp | 16 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qset/tst_qset.cpp | 16 |
2 files changed, 32 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qlinkedlist/tst_qlinkedlist.cpp b/tests/auto/corelib/tools/qlinkedlist/tst_qlinkedlist.cpp index 2e829bb05e..d3ace40164 100644 --- a/tests/auto/corelib/tools/qlinkedlist/tst_qlinkedlist.cpp +++ b/tests/auto/corelib/tools/qlinkedlist/tst_qlinkedlist.cpp @@ -204,6 +204,7 @@ private slots: void removeOneInt() const; void removeOneMovable() const; void removeOneComplex() const; + void reverseIterators() const; void startsWithInt() const; void startsWithMovable() const; void startsWithComplex() const; @@ -754,6 +755,21 @@ void tst_QLinkedList::removeOneComplex() const QCOMPARE(liveCount, Complex::getLiveCount()); } +void tst_QLinkedList::reverseIterators() const +{ + QLinkedList<int> l; + l << 1 << 2 << 3 << 4; + QLinkedList<int> lr = l; + std::reverse(lr.begin(), lr.end()); + const QLinkedList<int> &clr = lr; + QVERIFY(std::equal(l.begin(), l.end(), lr.rbegin())); + QVERIFY(std::equal(l.begin(), l.end(), lr.crbegin())); + QVERIFY(std::equal(l.begin(), l.end(), clr.rbegin())); + QVERIFY(std::equal(lr.rbegin(), lr.rend(), l.begin())); + QVERIFY(std::equal(lr.crbegin(), lr.crend(), l.begin())); + QVERIFY(std::equal(clr.rbegin(), clr.rend(), l.begin())); +} + template<typename T> void tst_QLinkedList::startsWith() const { diff --git a/tests/auto/corelib/tools/qset/tst_qset.cpp b/tests/auto/corelib/tools/qset/tst_qset.cpp index 134d257d64..fe4d81085c 100644 --- a/tests/auto/corelib/tools/qset/tst_qset.cpp +++ b/tests/auto/corelib/tools/qset/tst_qset.cpp @@ -65,6 +65,7 @@ private slots: void begin(); void end(); void insert(); + void reverseIterators(); void setOperations(); void stlIterator(); void stlMutableIterator(); @@ -555,6 +556,21 @@ void tst_QSet::insert() } } +void tst_QSet::reverseIterators() +{ + QSet<int> s; + s << 1 << 17 << 61 << 127 << 911; + std::vector<int> v(s.begin(), s.end()); + std::reverse(v.begin(), v.end()); + const QSet<int> &cs = s; + QVERIFY(std::equal(v.begin(), v.end(), s.rbegin())); + QVERIFY(std::equal(v.begin(), v.end(), s.crbegin())); + QVERIFY(std::equal(v.begin(), v.end(), cs.rbegin())); + QVERIFY(std::equal(s.rbegin(), s.rend(), v.begin())); + QVERIFY(std::equal(s.crbegin(), s.crend(), v.begin())); + QVERIFY(std::equal(cs.rbegin(), cs.rend(), v.begin())); +} + void tst_QSet::setOperations() { QSet<QString> set1, set2; |