diff options
-rw-r--r-- | src/corelib/tools/qvarlengtharray.h | 9 | ||||
-rw-r--r-- | src/corelib/tools/qvarlengtharray.qdoc | 60 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp | 16 |
3 files changed, 85 insertions, 0 deletions
diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index 2d8f922cb8..2933e40549 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -45,6 +45,7 @@ #ifdef Q_COMPILER_INITIALIZER_LISTS #include <initializer_list> #endif +#include <iterator> QT_BEGIN_NAMESPACE @@ -165,6 +166,8 @@ public: typedef T* iterator; typedef const T* const_iterator; + typedef std::reverse_iterator<iterator> reverse_iterator; + typedef std::reverse_iterator<const_iterator> const_reverse_iterator; inline iterator begin() { return ptr; } inline const_iterator begin() const { return ptr; } @@ -174,6 +177,12 @@ public: inline const_iterator end() const { return ptr + s; } inline const_iterator cend() const { return ptr + s; } inline const_iterator constEnd() const { return ptr + s; } + reverse_iterator rbegin() { return reverse_iterator(end()); } + reverse_iterator rend() { return reverse_iterator(begin()); } + const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } + const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } + const_reverse_iterator crbegin() const { return const_reverse_iterator(end()); } + const_reverse_iterator crend() const { return const_reverse_iterator(begin()); } iterator insert(const_iterator before, int n, const T &x); inline iterator insert(const_iterator before, const T &x) { return insert(before, 1, x); } iterator erase(const_iterator begin, const_iterator end); diff --git a/src/corelib/tools/qvarlengtharray.qdoc b/src/corelib/tools/qvarlengtharray.qdoc index 5533a7d663..1f3a73073f 100644 --- a/src/corelib/tools/qvarlengtharray.qdoc +++ b/src/corelib/tools/qvarlengtharray.qdoc @@ -459,6 +459,20 @@ Typedef for T *. Provided for STL compatibility. */ +/*! + \typedef QVarLengthArray::const_reverse_iterator + \since 5.6 + + Typedef for \c{std::reverse_iterator<const T*>}. Provided for STL compatibility. +*/ + +/*! + \typedef QVarLengthArray::reverse_iterator + \since 5.6 + + Typedef for \c{std::reverse_iterator<T*>}. Provided for STL compatibility. +*/ + /*! \fn void QVarLengthArray::prepend(const T &value) \since 4.8 @@ -573,6 +587,52 @@ \sa constBegin(), end() */ +/*! \fn QVarLengthArray::reverse_iterator QVarLengthArray::rbegin() + \since 5.6 + + Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to the first + item in the variable length array, in reverse order. + + \sa begin(), crbegin(), rend() +*/ + +/*! \fn QVarLengthArray::const_reverse_iterator QVarLengthArray::rbegin() const + \since 5.6 + \overload +*/ + +/*! \fn QVarLengthArray::const_reverse_iterator QVarLengthArray::crbegin() const + \since 5.6 + + Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing to the first + item in the variable length array, in reverse order. + + \sa begin(), rbegin(), rend() +*/ + +/*! \fn QVarLengthArray::reverse_iterator QVarLengthArray::rend() + \since 5.6 + + Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to one past + the last item in the variable length array, in reverse order. + + \sa end(), crend(), rbegin() +*/ + +/*! \fn QVarLengthArray::const_reverse_iterator QVarLengthArray::rend() const + \since 5.6 + \overload +*/ + +/*! \fn QVarLengthArray::const_reverse_iterator QVarLengthArray::crend() const + \since 5.6 + + Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing to one + past the last item in the variable length array, in reverse order. + + \sa end(), rend(), rbegin() +*/ + /*! \fn QVarLengthArray::iterator QVarLengthArray::erase(const_iterator pos) \since 4.8 diff --git a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp index 60f3009849..449fefbaa2 100644 --- a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp +++ b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp @@ -47,6 +47,7 @@ private slots: void appendCausingRealloc(); void resize(); void realloc(); + void reverseIterators(); void count(); void first(); void last(); @@ -563,6 +564,21 @@ void tst_QVarLengthArray::realloc() QVERIFY(reallocTestProceed); } +void tst_QVarLengthArray::reverseIterators() +{ + QVarLengthArray<int> v; + v << 1 << 2 << 3 << 4; + QVarLengthArray<int> vr = v; + std::reverse(vr.begin(), vr.end()); + const QVarLengthArray<int> &cvr = vr; + QVERIFY(std::equal(v.begin(), v.end(), vr.rbegin())); + QVERIFY(std::equal(v.begin(), v.end(), vr.crbegin())); + QVERIFY(std::equal(v.begin(), v.end(), cvr.rbegin())); + QVERIFY(std::equal(vr.rbegin(), vr.rend(), v.begin())); + QVERIFY(std::equal(vr.crbegin(), vr.crend(), v.begin())); + QVERIFY(std::equal(cvr.rbegin(), cvr.rend(), v.begin())); +} + void tst_QVarLengthArray::count() { // tests size(), count() and length(), since they're the same thing |