QJniArray: fix const_iterator declaration, make it default-constructible
Iterators are required to be default-constructible and value-initialized iterators must compare equal. In a const_iterator, the pointee should be const, not the iterator itself. Found during header review. Task-number: QTBUG-119952 Change-Id: I036c0a62ade8c59dc5d62c0823b375223719af3f Reviewed-by: Marc Mutz <marc.mutz@qt.io> (cherry picked from commit 100071af82963e712cb055e5d98795376d89e65c) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
6a5b47ecac
commit
6f959d4b05
@ -19,6 +19,8 @@ template <typename T> class QJniArray;
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
struct QJniArrayIterator
|
struct QJniArrayIterator
|
||||||
{
|
{
|
||||||
|
QJniArrayIterator() = default;
|
||||||
|
|
||||||
constexpr QJniArrayIterator(const QJniArrayIterator &other) noexcept = default;
|
constexpr QJniArrayIterator(const QJniArrayIterator &other) noexcept = default;
|
||||||
constexpr QJniArrayIterator(QJniArrayIterator &&other) noexcept = default;
|
constexpr QJniArrayIterator(QJniArrayIterator &&other) noexcept = default;
|
||||||
constexpr QJniArrayIterator &operator=(const QJniArrayIterator &other) noexcept = default;
|
constexpr QJniArrayIterator &operator=(const QJniArrayIterator &other) noexcept = default;
|
||||||
@ -49,13 +51,13 @@ struct QJniArrayIterator
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class QJniArray<T>;
|
using VT = std::remove_const_t<T>;
|
||||||
|
friend class QJniArray<VT>;
|
||||||
|
|
||||||
qsizetype m_index = 0;
|
qsizetype m_index = 0;
|
||||||
const QJniArray<T> *m_array = nullptr;
|
const QJniArray<VT> *m_array = nullptr;
|
||||||
|
|
||||||
QJniArrayIterator() = delete;
|
QJniArrayIterator(qsizetype index, const QJniArray<VT> *array)
|
||||||
QJniArrayIterator(qsizetype index, const QJniArray<T> *array)
|
|
||||||
: m_index(index), m_array(array)
|
: m_index(index), m_array(array)
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
@ -154,7 +156,7 @@ class QJniArray : public QJniArrayBase
|
|||||||
friend struct QJniArrayIterator<T>;
|
friend struct QJniArrayIterator<T>;
|
||||||
public:
|
public:
|
||||||
using Type = T;
|
using Type = T;
|
||||||
using const_iterator = const QJniArrayIterator<T>;
|
using const_iterator = QJniArrayIterator<const T>;
|
||||||
|
|
||||||
QJniArray() = default;
|
QJniArray() = default;
|
||||||
explicit QJniArray(jarray array) : QJniArrayBase(array) {}
|
explicit QJniArray(jarray array) : QJniArrayBase(array) {}
|
||||||
|
@ -17,6 +17,7 @@ public:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void size();
|
void size();
|
||||||
|
void operators();
|
||||||
};
|
};
|
||||||
|
|
||||||
using namespace QtJniTypes;
|
using namespace QtJniTypes;
|
||||||
@ -85,6 +86,22 @@ void tst_QJniArray::size()
|
|||||||
QCOMPARE(intArray.size(), 10);
|
QCOMPARE(intArray.size(), 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QJniArray::operators()
|
||||||
|
{
|
||||||
|
QByteArray bytes("abcde");
|
||||||
|
QJniArray<jbyte> array(bytes);
|
||||||
|
QVERIFY(array.isValid());
|
||||||
|
|
||||||
|
{
|
||||||
|
QJniArray<jbyte>::const_iterator it = {};
|
||||||
|
QCOMPARE(it, QJniArray<jbyte>::const_iterator{});
|
||||||
|
QCOMPARE_NE(array.begin(), array.end());
|
||||||
|
|
||||||
|
it = array.begin();
|
||||||
|
QCOMPARE(it, array.begin());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_MAIN(tst_QJniArray)
|
QTEST_MAIN(tst_QJniArray)
|
||||||
|
|
||||||
#include "tst_qjniarray.moc"
|
#include "tst_qjniarray.moc"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user