diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2011-08-29 17:49:48 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-17 09:10:57 +0100 |
commit | d823646db3e9f72569717dc656e5b2e4d3ce7709 (patch) | |
tree | 734f7f11b381eb890d406b05f93424e3081795d6 /tests/auto/other | |
parent | 7c7e47493edec987569a60e12456de5a2c62a230 (diff) |
containers: add C++11-style c{begin,end}() as alias for const{Begin,End}()
C++11 adds cbegin()/cend() functions for the same reason Qt has
constBegin()/constEnd(). This patch adds these functions to the
Qt containers with the same implementation as constBegin()/constEnd().
It also fixes the return types in the documentation of existing
constFind() functions (documentation only).
C++11 only adds cbegin()/cend() (and crbegin()/crend(), which Qt doesn't have).
In particular, it doesn't add cfind(), so I didn't supply these, even though
Qt comes with constFind().
This is a forward-port of https://qt.gitorious.org/qt/qt/merge_requests/1365.
Change-Id: Ida086b64246b24e25254eafbcb06c8e33388502b
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'tests/auto/other')
-rw-r--r-- | tests/auto/other/collections/tst_collections.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/tests/auto/other/collections/tst_collections.cpp b/tests/auto/other/collections/tst_collections.cpp index dc6d7f4b55..973938594f 100644 --- a/tests/auto/other/collections/tst_collections.cpp +++ b/tests/auto/other/collections/tst_collections.cpp @@ -550,6 +550,10 @@ void tst_Collections::list() QList<QString>::const_iterator cit = list.constBegin(); QVERIFY((*cit).toLower() == "xello"); QVERIFY(cit->toUpper() == "XELLO"); + + cit = list.cbegin(); + QVERIFY((*cit).toLower() == "xello"); + QVERIFY(cit->toUpper() == "XELLO"); } { @@ -967,6 +971,10 @@ void tst_Collections::linkedList() QLinkedList<QString>::const_iterator cit = list.constBegin(); QVERIFY((*cit).toLower() == "xello"); QVERIFY(cit->toUpper() == "XELLO"); + + cit = list.cbegin(); + QVERIFY((*cit).toLower() == "xello"); + QVERIFY(cit->toUpper() == "XELLO"); } { @@ -1607,6 +1615,10 @@ void tst_Collections::hash() QHash<int, QString>::const_iterator cit = hash.constBegin(); QVERIFY((*cit).toLower() == "xello"); QVERIFY(cit->toUpper() == "XELLO"); + + cit = hash.cbegin(); + QVERIFY((*cit).toLower() == "xello"); + QVERIFY(cit->toUpper() == "XELLO"); } { @@ -1924,6 +1936,10 @@ void tst_Collections::map() QMap<int, QString>::const_iterator cit = map.constBegin(); QVERIFY((*cit).toLower() == "xello"); QVERIFY(cit->toUpper() == "XELLO"); + + cit = map.cbegin(); + QVERIFY((*cit).toLower() == "xello"); + QVERIFY(cit->toUpper() == "XELLO"); } { @@ -2902,7 +2918,7 @@ void tst_Collections::linkedlist_stl() QCOMPARE(int(stdList.size()), elements.size()); std::list<QString>::const_iterator it = stdList.begin(); - QLinkedList<QString>::const_iterator it2 = list.constBegin(); + QLinkedList<QString>::const_iterator it2 = list.cbegin(); for (uint j = 0; j < stdList.size(); ++j, ++it, ++it2) QCOMPARE(*it, *it2); @@ -3001,9 +3017,11 @@ void instantiateContainer() #ifndef QT_NO_STL typename ContainerType::const_iterator constIt; constIt = constContainer.begin(); + constIt = container.cbegin(); container.constBegin(); constIt = constContainer.end(); + constIt = constContainer.cend(); container.constEnd(); Q_UNUSED(constIt) #endif |