summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2011-08-29 17:49:48 +0200
committerQt by Nokia <qt-info@nokia.com>2012-03-17 09:10:57 +0100
commitd823646db3e9f72569717dc656e5b2e4d3ce7709 (patch)
tree734f7f11b381eb890d406b05f93424e3081795d6 /src/corelib
parent7c7e47493edec987569a60e12456de5a2c62a230 (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 'src/corelib')
-rw-r--r--src/corelib/tools/qbytearray.cpp12
-rw-r--r--src/corelib/tools/qbytearray.h6
-rw-r--r--src/corelib/tools/qhash.cpp20
-rw-r--r--src/corelib/tools/qhash.h2
-rw-r--r--src/corelib/tools/qlinkedlist.cpp18
-rw-r--r--src/corelib/tools/qlinkedlist.h2
-rw-r--r--src/corelib/tools/qlist.cpp18
-rw-r--r--src/corelib/tools/qlist.h2
-rw-r--r--src/corelib/tools/qmap.cpp20
-rw-r--r--src/corelib/tools/qmap.h2
-rw-r--r--src/corelib/tools/qset.h2
-rw-r--r--src/corelib/tools/qset.qdoc18
-rw-r--r--src/corelib/tools/qstring.cpp18
-rw-r--r--src/corelib/tools/qstring.h6
-rw-r--r--src/corelib/tools/qvarlengtharray.h2
-rw-r--r--src/corelib/tools/qvarlengtharray.qdoc18
-rw-r--r--src/corelib/tools/qvector.cpp18
-rw-r--r--src/corelib/tools/qvector.h2
18 files changed, 184 insertions, 2 deletions
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<Node *>(p.begin()); }
inline const_iterator begin() const { return reinterpret_cast<Node *>(p.begin()); }
+ inline const_iterator cbegin() const { return reinterpret_cast<Node *>(p.begin()); }
inline const_iterator constBegin() const { return reinterpret_cast<Node *>(p.begin()); }
inline iterator end() { detach(); return reinterpret_cast<Node *>(p.end()); }
inline const_iterator end() const { return reinterpret_cast<Node *>(p.end()); }
+ inline const_iterator cend() const { return reinterpret_cast<Node *>(p.end()); }
inline const_iterator constEnd() const { return reinterpret_cast<Node *>(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<typename Hash::iterator &>(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<QChar*>(d->data()); }
inline QString::const_iterator QString::begin() const
{ return reinterpret_cast<const QChar*>(d->data()); }
+inline QString::const_iterator QString::cbegin() const
+{ return reinterpret_cast<const QChar*>(d->data()); }
inline QString::const_iterator QString::constBegin() const
{ return reinterpret_cast<const QChar*>(d->data()); }
inline QString::iterator QString::end()
{ detach(); return reinterpret_cast<QChar*>(d->data() + d->size); }
inline QString::const_iterator QString::end() const
{ return reinterpret_cast<const QChar*>(d->data() + d->size); }
+inline QString::const_iterator QString::cend() const
+{ return reinterpret_cast<const QChar*>(d->data() + d->size); }
inline QString::const_iterator QString::constEnd() const
{ return reinterpret_cast<const QChar*>(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); }