QList: add {const_,reverse_iterator}, {c,}r{begin,end}()
[ChangeLog][QtCore][QList] Added rbegin(), crbegin(), rend(), crend(), and reverse_iterator and const_reverse_iterator typedefs. Task-number: QTBUG-25919 Change-Id: Icce870c22931e68cdcedd1519651bfa374ac44af Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
dfb00bd479
commit
f7b5f0cfd2
@ -1048,6 +1048,52 @@ void **QListData::erase(void **xi)
|
||||
\sa constBegin(), end()
|
||||
*/
|
||||
|
||||
/*! \fn QList::reverse_iterator QList::rbegin()
|
||||
\since 5.6
|
||||
|
||||
Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to the first
|
||||
item in the list, in reverse order.
|
||||
|
||||
\sa begin(), crbegin(), rend()
|
||||
*/
|
||||
|
||||
/*! \fn QList::const_reverse_iterator QList::rbegin() const
|
||||
\since 5.6
|
||||
\overload
|
||||
*/
|
||||
|
||||
/*! \fn QList::const_reverse_iterator QList::crbegin() const
|
||||
\since 5.6
|
||||
|
||||
Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing to the first
|
||||
item in the list, in reverse order.
|
||||
|
||||
\sa begin(), rbegin(), rend()
|
||||
*/
|
||||
|
||||
/*! \fn QList::reverse_iterator QList::rend()
|
||||
\since 5.6
|
||||
|
||||
Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to one past
|
||||
the last item in the list, in reverse order.
|
||||
|
||||
\sa end(), crend(), rbegin()
|
||||
*/
|
||||
|
||||
/*! \fn QList::const_reverse_iterator QList::rend() const
|
||||
\since 5.6
|
||||
\overload
|
||||
*/
|
||||
|
||||
/*! \fn QList::const_reverse_iterator QList::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 list, in reverse order.
|
||||
|
||||
\sa end(), rend(), rbegin()
|
||||
*/
|
||||
|
||||
/*! \fn QList::iterator QList::erase(iterator pos)
|
||||
|
||||
Removes the item associated with the iterator \a pos from the
|
||||
@ -1118,6 +1164,38 @@ void **QListData::erase(void **xi)
|
||||
Typedef for const T &. Provided for STL compatibility.
|
||||
*/
|
||||
|
||||
/*! \typedef QList::reverse_iterator
|
||||
\since 5.6
|
||||
|
||||
The QList::reverse_iterator typedef provides an STL-style non-const
|
||||
reverse iterator for QList.
|
||||
|
||||
It is simply a typedef for \c{std::reverse_iterator<iterator>}.
|
||||
|
||||
\warning Iterators on implicitly shared containers do not work
|
||||
exactly like STL-iterators. You should avoid copying a container
|
||||
while iterators are active on that container. For more information,
|
||||
read \l{Implicit sharing iterator problem}.
|
||||
|
||||
\sa QList::rbegin(), QList::rend(), QList::const_reverse_iterator, QList::iterator
|
||||
*/
|
||||
|
||||
/*! \typedef QList::const_reverse_iterator
|
||||
\since 5.6
|
||||
|
||||
The QList::const_reverse_iterator typedef provides an STL-style const
|
||||
reverse iterator for QList.
|
||||
|
||||
It is simply a typedef for \c{std::reverse_iterator<const_iterator>}.
|
||||
|
||||
\warning Iterators on implicitly shared containers do not work
|
||||
exactly like STL-iterators. You should avoid copying a container
|
||||
while iterators are active on that container. For more information,
|
||||
read \l{Implicit sharing iterator problem}.
|
||||
|
||||
\sa QList::rbegin(), QList::rend(), QList::reverse_iterator, QList::const_iterator
|
||||
*/
|
||||
|
||||
/*! \fn int QList::count() const
|
||||
|
||||
Returns the number of items in the list. This is effectively the
|
||||
|
@ -291,6 +291,8 @@ public:
|
||||
friend class const_iterator;
|
||||
|
||||
// stl style
|
||||
typedef std::reverse_iterator<iterator> reverse_iterator;
|
||||
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
|
||||
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()); }
|
||||
@ -299,6 +301,12 @@ public:
|
||||
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()); }
|
||||
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(iterator before, const T &t);
|
||||
iterator erase(iterator pos);
|
||||
iterator erase(iterator first, iterator last);
|
||||
|
@ -349,6 +349,9 @@ private slots:
|
||||
void replaceOptimal() const;
|
||||
void replaceMovable() const;
|
||||
void replaceComplex() const;
|
||||
void reverseIteratorsOptimal() const;
|
||||
void reverseIteratorsMovable() const;
|
||||
void reverseIteratorsComplex() const;
|
||||
void startsWithOptimal() const;
|
||||
void startsWithMovable() const;
|
||||
void startsWithComplex() const;
|
||||
@ -416,6 +419,7 @@ private:
|
||||
template<typename T> void removeAt() const;
|
||||
template<typename T> void removeOne() const;
|
||||
template<typename T> void replace() const;
|
||||
template<typename T> void reverseIterators() const;
|
||||
template<typename T> void startsWith() const;
|
||||
template<typename T> void swap() const;
|
||||
template<typename T> void takeAt() const;
|
||||
@ -1239,6 +1243,43 @@ void tst_QList::replaceComplex() const
|
||||
QCOMPARE(liveCount, Complex::getLiveCount());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void tst_QList::reverseIterators() const
|
||||
{
|
||||
QList<T> v;
|
||||
v << T_CAT << T_DOG << T_BLAH << T_BAZ;
|
||||
QList<T> vr = v;
|
||||
std::reverse(vr.begin(), vr.end());
|
||||
const QList<T> &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_QList::reverseIteratorsOptimal() const
|
||||
{
|
||||
const int liveCount = Optimal::getLiveCount();
|
||||
reverseIterators<Optimal>();
|
||||
QCOMPARE(liveCount, Optimal::getLiveCount());
|
||||
}
|
||||
|
||||
void tst_QList::reverseIteratorsMovable() const
|
||||
{
|
||||
const int liveCount = Movable::getLiveCount();
|
||||
reverseIterators<Movable>();
|
||||
QCOMPARE(liveCount, Movable::getLiveCount());
|
||||
}
|
||||
|
||||
void tst_QList::reverseIteratorsComplex() const
|
||||
{
|
||||
const int liveCount = Complex::getLiveCount();
|
||||
reverseIterators<Complex>();
|
||||
QCOMPARE(liveCount, Complex::getLiveCount());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void tst_QList::startsWith() const
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user