QJniArray: make iterator strongly ordered
Required for making the iterator random access. Implement compareThreeWay, add tests. Comparing iterators operating on different containers is undefined behavior, so assert if they don't match (even if they are different QJniArrays referencing the same Java array). Based on review comments. Task-number: QTBUG-126150 Change-Id: Ib3b94558fc66fb9cff19139d2110c6bbd4ac14b5 Reviewed-by: Soheil Armin <soheil.armin@qt.io> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> (cherry picked from commit d04f38f6f5e49a81211ab598ba23049dc4ef1507) Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
708b84be11
commit
46ed4e47d2
@ -78,7 +78,13 @@ private:
|
||||
Q_ASSERT(lhs.m_array == rhs.m_array);
|
||||
return lhs.m_index == rhs.m_index;
|
||||
}
|
||||
Q_DECLARE_EQUALITY_COMPARABLE(QJniArrayIterator)
|
||||
friend constexpr Qt::strong_ordering compareThreeWay(const QJniArrayIterator &lhs,
|
||||
const QJniArrayIterator &rhs)
|
||||
{
|
||||
Q_ASSERT(lhs.m_array == rhs.m_array);
|
||||
return Qt::compareThreeWay(lhs.m_index, rhs.m_index);
|
||||
}
|
||||
Q_DECLARE_STRONGLY_ORDERED(QJniArrayIterator)
|
||||
|
||||
using VT = std::remove_const_t<T>;
|
||||
friend class QJniArray<VT>;
|
||||
|
@ -20,6 +20,7 @@ private slots:
|
||||
void invalidArraysAreEmpty();
|
||||
void size();
|
||||
void operators();
|
||||
void ordering();
|
||||
void toContainer();
|
||||
};
|
||||
|
||||
@ -263,6 +264,18 @@ void tst_QJniArray::operators()
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QJniArray::ordering()
|
||||
{
|
||||
QByteArray bytes("abcde");
|
||||
QJniArray array(bytes);
|
||||
|
||||
auto arrayBegin = array.begin();
|
||||
auto arrayEnd = array.end();
|
||||
QCOMPARE(arrayBegin, arrayBegin);
|
||||
QCOMPARE_LT(arrayBegin, arrayEnd);
|
||||
QCOMPARE_GT(arrayEnd, arrayBegin);
|
||||
}
|
||||
|
||||
void tst_QJniArray::toContainer()
|
||||
{
|
||||
std::vector<jchar> charVector{u'a', u'b', u'c'};
|
||||
|
Loading…
x
Reference in New Issue
Block a user