diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp index b6719c9536..db22a774f4 100644 --- a/src/corelib/tools/qbytearray.cpp +++ b/src/corelib/tools/qbytearray.cpp @@ -799,6 +799,12 @@ const QConstByteArrayData<1> QByteArray::shared_empty = { { Q_REFCOUNT_INITIALIZ \internal */ +/*! \fn QByteArray::const_iterator QByteArray::cbegin() const + \since 5.0 + + \internal +*/ + /*! \fn QByteArray::const_iterator QByteArray::constBegin() const \internal @@ -814,6 +820,12 @@ const QConstByteArrayData<1> QByteArray::shared_empty = { { Q_REFCOUNT_INITIALIZ \internal */ +/*! \fn QByteArray::const_iterator QByteArray::cend() const + \since 5.0 + + \internal +*/ + /*! \fn QByteArray::const_iterator QByteArray::constEnd() const \internal diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/tools/qbytearray.h index 09c43988fd..7711d7349e 100644 --- a/src/corelib/tools/qbytearray.h +++ b/src/corelib/tools/qbytearray.h @@ -358,9 +358,11 @@ public: typedef const_iterator ConstIterator; iterator begin(); const_iterator begin() const; + const_iterator cbegin() const; const_iterator constBegin() const; iterator end(); const_iterator end() const; + const_iterator cend() const; const_iterator constEnd() const; // stl compatibility @@ -492,12 +494,16 @@ inline QByteArray::iterator QByteArray::begin() { detach(); return d->data(); } inline QByteArray::const_iterator QByteArray::begin() const { return d->data(); } +inline QByteArray::const_iterator QByteArray::cbegin() const +{ return d->data(); } inline QByteArray::const_iterator QByteArray::constBegin() const { return d->data(); } inline QByteArray::iterator QByteArray::end() { detach(); return d->data() + d->size; } inline QByteArray::const_iterator QByteArray::end() const { return d->data() + d->size; } +inline QByteArray::const_iterator QByteArray::cend() const +{ return d->data() + d->size; } inline QByteArray::const_iterator QByteArray::constEnd() const { return d->data() + d->size; } inline QByteArray &QByteArray::operator+=(char c) diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp index d5703e8b2a..62fc6c5d86 100644 --- a/src/corelib/tools/qhash.cpp +++ b/src/corelib/tools/qhash.cpp @@ -1045,6 +1045,15 @@ void QHashData::checkSanity() \overload */ +/*! \fn QHash::const_iterator QHash::cbegin() const + \since 5.0 + + Returns a const \l{STL-style iterator} pointing to the first item + in the hash. + + \sa begin(), cend() +*/ + /*! \fn QHash::const_iterator QHash::constBegin() const Returns a const \l{STL-style iterator} pointing to the first item @@ -1074,6 +1083,15 @@ void QHashData::checkSanity() \sa constBegin(), end() */ +/*! \fn QHash::const_iterator QHash::cend() const + \since 5.0 + + Returns a const \l{STL-style iterator} pointing to the imaginary + item after the last item in the hash. + + \sa cbegin(), end() +*/ + /*! \fn QHash::iterator QHash::erase(iterator pos) Removes the (key, value) pair associated with the iterator \a pos @@ -1114,7 +1132,7 @@ void QHashData::checkSanity() \overload */ -/*! \fn QHash::iterator QHash::constFind(const Key &key) const +/*! \fn QHash::const_iterator QHash::constFind(const Key &key) const \since 4.1 Returns an iterator pointing to the item with the \a key in the diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index 9e4007c26e..55fa788543 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -440,9 +440,11 @@ public: // STL style inline iterator begin() { detach(); return iterator(d->firstNode()); } inline const_iterator begin() const { return const_iterator(d->firstNode()); } + inline const_iterator cbegin() const { return const_iterator(d->firstNode()); } inline const_iterator constBegin() const { return const_iterator(d->firstNode()); } inline iterator end() { detach(); return iterator(e); } inline const_iterator end() const { return const_iterator(e); } + inline const_iterator cend() const { return const_iterator(e); } inline const_iterator constEnd() const { return const_iterator(e); } iterator erase(iterator it); diff --git a/src/corelib/tools/qlinkedlist.cpp b/src/corelib/tools/qlinkedlist.cpp index b31ef3e5e9..50f6f447b2 100644 --- a/src/corelib/tools/qlinkedlist.cpp +++ b/src/corelib/tools/qlinkedlist.cpp @@ -330,6 +330,15 @@ const QLinkedListData QLinkedListData::shared_null = { \overload */ +/*! \fn QLinkedList::const_iterator QLinkedList::cbegin() const + \since 5.0 + + Returns a const \l{STL-style iterator} pointing to the first item + in the list. + + \sa begin(), cend() +*/ + /*! \fn QLinkedList::const_iterator QLinkedList::constBegin() const Returns a const \l{STL-style iterator} pointing to the first item @@ -351,6 +360,15 @@ const QLinkedListData QLinkedListData::shared_null = { \overload */ +/*! \fn QLinkedList::const_iterator QLinkedList::cend() const + \since 5.0 + + Returns a const \l{STL-style iterator} pointing to the imaginary + item after the last item in the list. + + \sa cbegin(), end() +*/ + /*! \fn QLinkedList::const_iterator QLinkedList::constEnd() const Returns a const \l{STL-style iterator} pointing to the imaginary diff --git a/src/corelib/tools/qlinkedlist.h b/src/corelib/tools/qlinkedlist.h index 2e6d05ac35..2b23fc230c 100644 --- a/src/corelib/tools/qlinkedlist.h +++ b/src/corelib/tools/qlinkedlist.h @@ -180,9 +180,11 @@ public: // stl style inline iterator begin() { detach(); return e->n; } inline const_iterator begin() const { return e->n; } + inline const_iterator cbegin() const { return e->n; } inline const_iterator constBegin() const { return e->n; } inline iterator end() { detach(); return e; } inline const_iterator end() const { return e; } + inline const_iterator cend() const { return e; } inline const_iterator constEnd() const { return e; } iterator insert(iterator before, const T &t); iterator erase(iterator pos); diff --git a/src/corelib/tools/qlist.cpp b/src/corelib/tools/qlist.cpp index 263045a25d..9b40e2d37a 100644 --- a/src/corelib/tools/qlist.cpp +++ b/src/corelib/tools/qlist.cpp @@ -921,6 +921,15 @@ void **QListData::erase(void **xi) \overload */ +/*! \fn QList::const_iterator QList::cbegin() const + \since 5.0 + + Returns a const \l{STL-style iterator} pointing to the first item + in the list. + + \sa begin(), cend() +*/ + /*! \fn QList::const_iterator QList::constBegin() const Returns a const \l{STL-style iterator} pointing to the first item @@ -942,6 +951,15 @@ void **QListData::erase(void **xi) \overload */ +/*! \fn QList::const_iterator QList::cend() const + \since 5.0 + + Returns a const \l{STL-style iterator} pointing to the imaginary + item after the last item in the list. + + \sa cbegin(), end() +*/ + /*! \fn QList::const_iterator QList::constEnd() const Returns a const \l{STL-style iterator} pointing to the imaginary diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index bf6933732c..3d55b3002d 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -262,9 +262,11 @@ public: // stl style inline iterator begin() { detach(); return reinterpret_cast(p.begin()); } inline const_iterator begin() const { return reinterpret_cast(p.begin()); } + inline const_iterator cbegin() const { return reinterpret_cast(p.begin()); } inline const_iterator constBegin() const { return reinterpret_cast(p.begin()); } inline iterator end() { detach(); return reinterpret_cast(p.end()); } inline const_iterator end() const { return reinterpret_cast(p.end()); } + inline const_iterator cend() const { return reinterpret_cast(p.end()); } inline const_iterator constEnd() const { return reinterpret_cast(p.end()); } iterator insert(iterator before, const T &t); iterator erase(iterator pos); diff --git a/src/corelib/tools/qmap.cpp b/src/corelib/tools/qmap.cpp index 103d074941..e0b53fc64e 100644 --- a/src/corelib/tools/qmap.cpp +++ b/src/corelib/tools/qmap.cpp @@ -682,6 +682,15 @@ void QMapData::dump() \overload */ +/*! \fn QMap::const_iterator QMap::cbegin() const + \since 5.0 + + Returns a const \l{STL-style iterator} pointing to the first item + in the map. + + \sa begin(), cend() +*/ + /*! \fn QMap::const_iterator QMap::constBegin() const Returns a const \l{STL-style iterator} pointing to the first item @@ -703,6 +712,15 @@ void QMapData::dump() \overload */ +/*! \fn QMap::const_iterator QMap::cend() const + \since 5.0 + + Returns a const \l{STL-style iterator} pointing to the imaginary + item after the last item in the map. + + \sa cbegin(), end() +*/ + /*! \fn QMap::const_iterator QMap::constEnd() const Returns a const \l{STL-style iterator} pointing to the imaginary @@ -744,7 +762,7 @@ void QMapData::dump() \overload */ -/*! \fn QMap::iterator QMap::constFind(const Key &key) const +/*! \fn QMap::const_iterator QMap::constFind(const Key &key) const \since 4.1 Returns an const iterator pointing to the item with key \a key in the diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h index 515b60bea6..a00f9477f6 100644 --- a/src/corelib/tools/qmap.h +++ b/src/corelib/tools/qmap.h @@ -362,12 +362,14 @@ public: // STL style inline iterator begin() { detach(); return iterator(e->forward[0]); } inline const_iterator begin() const { return const_iterator(e->forward[0]); } + inline const_iterator cbegin() const { return const_iterator(e->forward[0]); } inline const_iterator constBegin() const { return const_iterator(e->forward[0]); } inline iterator end() { detach(); return iterator(e); } inline const_iterator end() const { return const_iterator(e); } + inline const_iterator cend() const { return const_iterator(e); } inline const_iterator constEnd() const { return const_iterator(e); } iterator erase(iterator it); diff --git a/src/corelib/tools/qset.h b/src/corelib/tools/qset.h index 7750cd1147..e85c770d42 100644 --- a/src/corelib/tools/qset.h +++ b/src/corelib/tools/qset.h @@ -164,9 +164,11 @@ public: // STL style inline iterator begin() { return q_hash.begin(); } inline const_iterator begin() const { return q_hash.begin(); } + inline const_iterator cbegin() const { return q_hash.begin(); } inline const_iterator constBegin() const { return q_hash.constBegin(); } inline iterator end() { return q_hash.end(); } inline const_iterator end() const { return q_hash.end(); } + inline const_iterator cend() const { return q_hash.end(); } inline const_iterator constEnd() const { return q_hash.constEnd(); } iterator erase(iterator i) { return q_hash.erase(reinterpret_cast(i)); } diff --git a/src/corelib/tools/qset.qdoc b/src/corelib/tools/qset.qdoc index b33064e1b8..139b017966 100644 --- a/src/corelib/tools/qset.qdoc +++ b/src/corelib/tools/qset.qdoc @@ -343,6 +343,15 @@ item in the set. */ +/*! \fn QSet::const_iterator QSet::cbegin() const + \since 5.0 + + Returns a const \l{STL-style iterator} positioned at the first + item in the set. + + \sa begin(), cend() +*/ + /*! \fn QSet::const_iterator QSet::constBegin() const Returns a const \l{STL-style iterator} positioned at the first @@ -367,6 +376,15 @@ imaginary item after the last item in the set. */ +/*! \fn QSet::const_iterator QSet::cend() const + \since 5.0 + + Returns a const \l{STL-style iterator} pointing to the imaginary + item after the last item in the set. + + \sa cbegin(), end() +*/ + /*! \fn QSet::const_iterator QSet::constEnd() const Returns a const \l{STL-style iterator} pointing to the imaginary diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 083abcbaad..57990c57ac 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -859,6 +859,15 @@ int QString::grow(int size) \overload begin() */ +/*! \fn QString::const_iterator QString::cbegin() const + \since 5.0 + + Returns a const \l{STL-style iterator} pointing to the first character + in the string. + + \sa begin(), cend() +*/ + /*! \fn QString::const_iterator QString::constBegin() const Returns a const \l{STL-style iterator} pointing to the first character @@ -880,6 +889,15 @@ int QString::grow(int size) \overload end() */ +/*! \fn QString::const_iterator QString::cend() const + \since 5.0 + + Returns a const \l{STL-style iterator} pointing to the imaginary + item after the last item in the list. + + \sa cbegin(), end() +*/ + /*! \fn QString::const_iterator QString::constEnd() const Returns a const \l{STL-style iterator} pointing to the imaginary diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index 4d02fbe66d..437e98b662 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -558,9 +558,11 @@ public: typedef const_iterator ConstIterator; iterator begin(); const_iterator begin() const; + const_iterator cbegin() const; const_iterator constBegin() const; iterator end(); const_iterator end() const; + const_iterator cend() const; const_iterator constEnd() const; // STL compatibility @@ -904,12 +906,16 @@ inline QString::iterator QString::begin() { detach(); return reinterpret_cast(d->data()); } inline QString::const_iterator QString::begin() const { return reinterpret_cast(d->data()); } +inline QString::const_iterator QString::cbegin() const +{ return reinterpret_cast(d->data()); } inline QString::const_iterator QString::constBegin() const { return reinterpret_cast(d->data()); } inline QString::iterator QString::end() { detach(); return reinterpret_cast(d->data() + d->size); } inline QString::const_iterator QString::end() const { return reinterpret_cast(d->data() + d->size); } +inline QString::const_iterator QString::cend() const +{ return reinterpret_cast(d->data() + d->size); } inline QString::const_iterator QString::constEnd() const { return reinterpret_cast(d->data() + d->size); } inline bool QString::contains(const QString &s, Qt::CaseSensitivity cs) const diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index a6613a3774..4e042f765e 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -160,9 +160,11 @@ public: inline iterator begin() { return ptr; } inline const_iterator begin() const { return ptr; } + inline const_iterator cbegin() const { return ptr; } inline const_iterator constBegin() const { return ptr; } inline iterator end() { return ptr + s; } inline const_iterator end() const { return ptr + s; } + inline const_iterator cend() const { return ptr + s; } inline const_iterator constEnd() const { return ptr + s; } iterator insert(iterator before, int n, const T &x); inline iterator insert(iterator before, const T &x) { return insert(before, 1, x); } diff --git a/src/corelib/tools/qvarlengtharray.qdoc b/src/corelib/tools/qvarlengtharray.qdoc index e1dc2bee9a..e92f91aa47 100644 --- a/src/corelib/tools/qvarlengtharray.qdoc +++ b/src/corelib/tools/qvarlengtharray.qdoc @@ -451,6 +451,15 @@ \overload */ +/*! \fn QVarLengthArray::const_iterator QVarLengthArray::cbegin() const + \since 5.0 + + Returns a const \l{STL-style iterator} pointing to the first item + in the array. + + \sa begin(), cend() +*/ + /*! \fn QVarLengthArray::const_iterator QVarLengthArray::constBegin() const \since 4.8 @@ -475,6 +484,15 @@ \overload */ +/*! \fn QVarLengthArray::const_iterator QVarLengthArray::cend() const + \since 5.0 + + Returns a const \l{STL-style iterator} pointing to the imaginary + item after the last item in the array. + + \sa cbegin(), end() +*/ + /*! \fn QVarLengthArray::const_iterator QVarLengthArray::constEnd() const \since 4.8 diff --git a/src/corelib/tools/qvector.cpp b/src/corelib/tools/qvector.cpp index 75c219bbc9..0f5c2d3cd9 100644 --- a/src/corelib/tools/qvector.cpp +++ b/src/corelib/tools/qvector.cpp @@ -698,6 +698,15 @@ int QVectorData::grow(int sizeofTypedData, int size, int sizeofT, bool excessive \overload */ +/*! \fn QVector::const_iterator QVector::cbegin() const + \since 5.0 + + Returns a const \l{STL-style iterator} pointing to the first item + in the vector. + + \sa begin(), cend() +*/ + /*! \fn QVector::const_iterator QVector::constBegin() const Returns a const \l{STL-style iterator} pointing to the first item @@ -719,6 +728,15 @@ int QVectorData::grow(int sizeofTypedData, int size, int sizeofT, bool excessive \overload */ +/*! \fn QVector::const_iterator QVector::cend() const + \since 5.0 + + Returns a const \l{STL-style iterator} pointing to the imaginary + item after the last item in the vector. + + \sa cbegin(), end() +*/ + /*! \fn QVector::const_iterator QVector::constEnd() const Returns a const \l{STL-style iterator} pointing to the imaginary diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index 4230e55ff5..09aabe5d73 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -245,9 +245,11 @@ public: #endif inline iterator begin() { detach(); return p->array; } inline const_iterator begin() const { return p->array; } + inline const_iterator cbegin() const { return p->array; } inline const_iterator constBegin() const { return p->array; } inline iterator end() { detach(); return p->array + d->size; } inline const_iterator end() const { return p->array + d->size; } + inline const_iterator cend() const { return p->array + d->size; } inline const_iterator constEnd() const { return p->array + d->size; } iterator insert(iterator before, int n, const T &x); inline iterator insert(iterator before, const T &x) { return insert(before, 1, x); } diff --git a/tests/auto/corelib/tools/qmap/tst_qmap.cpp b/tests/auto/corelib/tools/qmap/tst_qmap.cpp index 79b0a931cb..7d0ef7d7e4 100644 --- a/tests/auto/corelib/tools/qmap/tst_qmap.cpp +++ b/tests/auto/corelib/tools/qmap/tst_qmap.cpp @@ -285,6 +285,8 @@ void tst_QMap::beginEnd() QVERIFY( map.constBegin() == map.constEnd() ); map.insert( "0", "a" ); map.insert( "1", "b" ); + QVERIFY( map.constBegin() == map.cbegin() ); + QVERIFY( map.constEnd() == map.cend() ); // make a copy. const function shouldn't detach StringMap map2 = map; diff --git a/tests/auto/corelib/tools/qset/tst_qset.cpp b/tests/auto/corelib/tools/qset/tst_qset.cpp index d7d8c99071..ee83339d50 100644 --- a/tests/auto/corelib/tools/qset/tst_qset.cpp +++ b/tests/auto/corelib/tools/qset/tst_qset.cpp @@ -393,9 +393,9 @@ void tst_QSet::begin() { QSet::const_iterator i = set1.constBegin(); - QSet::const_iterator j = set1.constBegin(); + QSet::const_iterator j = set1.cbegin(); QSet::const_iterator k = set2.constBegin(); - QSet::const_iterator ell = set2.constBegin(); + QSet::const_iterator ell = set2.cbegin(); QVERIFY(i == j); QVERIFY(k == ell); @@ -407,9 +407,9 @@ void tst_QSet::begin() { QSet::const_iterator i = set1.constBegin(); - QSet::const_iterator j = set1.constBegin(); + QSet::const_iterator j = set1.cbegin(); QSet::const_iterator k = set2.constBegin(); - QSet::const_iterator ell = set2.constBegin(); + QSet::const_iterator ell = set2.cbegin(); QVERIFY(i == j); QVERIFY(k == ell); @@ -421,9 +421,9 @@ void tst_QSet::begin() { QSet::const_iterator i = set1.constBegin(); - QSet::const_iterator j = set1.constBegin(); + QSet::const_iterator j = set1.cbegin(); QSet::const_iterator k = set2.constBegin(); - QSet::const_iterator ell = set2.constBegin(); + QSet::const_iterator ell = set2.cbegin(); QVERIFY(i == j); QVERIFY(k == ell); @@ -439,9 +439,9 @@ void tst_QSet::end() { QSet::const_iterator i = set1.constEnd(); - QSet::const_iterator j = set1.constEnd(); + QSet::const_iterator j = set1.cend(); QSet::const_iterator k = set2.constEnd(); - QSet::const_iterator ell = set2.constEnd(); + QSet::const_iterator ell = set2.cend(); QVERIFY(i == j); QVERIFY(k == ell); @@ -456,9 +456,9 @@ void tst_QSet::end() { QSet::const_iterator i = set1.constEnd(); - QSet::const_iterator j = set1.constEnd(); + QSet::const_iterator j = set1.cend(); QSet::const_iterator k = set2.constEnd(); - QSet::const_iterator ell = set2.constEnd(); + QSet::const_iterator ell = set2.cend(); QVERIFY(i == j); QVERIFY(k == ell); @@ -473,9 +473,9 @@ void tst_QSet::end() { QSet::const_iterator i = set1.constEnd(); - QSet::const_iterator j = set1.constEnd(); + QSet::const_iterator j = set1.cend(); QSet::const_iterator k = set2.constEnd(); - QSet::const_iterator ell = set2.constEnd(); + QSet::const_iterator ell = set2.cend(); QVERIFY(i == j); QVERIFY(k == ell); 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::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::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::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::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::const_iterator it = stdList.begin(); - QLinkedList::const_iterator it2 = list.constBegin(); + QLinkedList::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