QJniArray: implement offset dereference operator
The last requirement for making the iterator random-access, so change category type. Based on review comments. Task-number: QTBUG-126150 Change-Id: I617f38f92d0f9279781e62ea3ab1929dbf6a07cd Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> (cherry picked from commit e4b2d7607c0243f2a7ca3f38f59e8532c543fcc7) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
0db64ca53b
commit
d9c38b66aa
@ -37,12 +37,18 @@ struct QJniArrayIterator
|
|||||||
using pointer = T *;
|
using pointer = T *;
|
||||||
using reference = T; // difference to container requirements
|
using reference = T; // difference to container requirements
|
||||||
using const_reference = reference;
|
using const_reference = reference;
|
||||||
using iterator_category = std::bidirectional_iterator_tag;
|
using iterator_category = std::random_access_iterator_tag;
|
||||||
|
|
||||||
const_reference operator*() const
|
const_reference operator*() const
|
||||||
{
|
{
|
||||||
return m_array->at(m_index);
|
return m_array->at(m_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const_reference operator[](difference_type n) const
|
||||||
|
{
|
||||||
|
return m_array->at(m_index + n);
|
||||||
|
}
|
||||||
|
|
||||||
friend QJniArrayIterator &operator++(QJniArrayIterator &that) noexcept
|
friend QJniArrayIterator &operator++(QJniArrayIterator &that) noexcept
|
||||||
{
|
{
|
||||||
++that.m_index;
|
++that.m_index;
|
||||||
|
@ -328,7 +328,7 @@
|
|||||||
/*!
|
/*!
|
||||||
\typedef QJniArray::const_iterator
|
\typedef QJniArray::const_iterator
|
||||||
|
|
||||||
A bi-directional, const iterator for QJniArray.
|
A random-access, const iterator for QJniArray.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -251,6 +251,9 @@ void tst_QJniArray::operators()
|
|||||||
QCOMPARE(*it, 'd');
|
QCOMPARE(*it, 'd');
|
||||||
it = array.size() - it;
|
it = array.size() - it;
|
||||||
QCOMPARE(*it, 'c');
|
QCOMPARE(*it, 'c');
|
||||||
|
|
||||||
|
QCOMPARE(it[1], 'd');
|
||||||
|
QCOMPARE(it[-1], 'b');
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
auto it = array.rbegin();
|
auto it = array.rbegin();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user