QFuture::const_iterator: use modernize comparisons
Replace class operators operator==(), operator!=() of QFuture::const_iterator: to friend method comparesEqual() and Q_DECLARE_EQUALITY_COMPARABLE macro. Task-number: QTBUG-120304 Change-Id: Ifa264b83f4d5623db99820847ab9a800cca99be2 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
This commit is contained in:
parent
5ea2481556
commit
ec88e63f2a
@ -183,8 +183,6 @@ QT_WARNING_POP
|
||||
{ future = o.future; index = o.index; return *this; }
|
||||
inline const T &operator*() const { return future->d.resultReference(index); }
|
||||
inline const T *operator->() const { return future->d.resultPointer(index); }
|
||||
inline bool operator!=(const const_iterator &other) const { return index != other.index; }
|
||||
inline bool operator==(const const_iterator &o) const { return !operator!=(o); }
|
||||
inline const_iterator &operator++()
|
||||
{ index = advanceIndex(index, 1); return *this; }
|
||||
inline const_iterator &operator--()
|
||||
@ -213,6 +211,12 @@ QT_WARNING_POP
|
||||
{ return const_iterator(k.future, k.advanceIndex(k.index, j)); }
|
||||
|
||||
private:
|
||||
friend bool comparesEqual(const const_iterator &lhs, const const_iterator &rhs) noexcept
|
||||
{
|
||||
return lhs.index == rhs.index;
|
||||
}
|
||||
Q_DECLARE_EQUALITY_COMPARABLE(const_iterator)
|
||||
|
||||
/*! \internal
|
||||
|
||||
Advances the iterator index \a idx \a n steps, waits for the
|
||||
|
@ -613,17 +613,17 @@
|
||||
Returns a pointer to the current result.
|
||||
*/
|
||||
|
||||
/*! \fn template <typename T> bool QFuture<T>::const_iterator::operator!=(const const_iterator &other) const
|
||||
/*! \fn template <typename T> bool QFuture<T>::const_iterator::operator!=(const const_iterator &lhs, const const_iterator &rhs)
|
||||
|
||||
Returns \c true if \a other points to a different result than this iterator;
|
||||
Returns \c true if \a lhs points to a different result than \a rhs iterator;
|
||||
otherwise returns \c false.
|
||||
|
||||
\sa operator==()
|
||||
*/
|
||||
|
||||
/*! \fn template <typename T> bool QFuture<T>::const_iterator::operator==(const const_iterator &other) const
|
||||
/*! \fn template <typename T> bool QFuture<T>::const_iterator::operator==(const const_iterator &lhs, const const_iterator &rhs)
|
||||
|
||||
Returns \c true if \a other points to the same result as this iterator;
|
||||
Returns \c true if \a lhs points to the same result as \a rhs iterator;
|
||||
otherwise returns \c false.
|
||||
|
||||
\sa operator!=()
|
||||
|
@ -16,6 +16,7 @@ qt_internal_add_test(tst_qfuture
|
||||
tst_qfuture.cpp
|
||||
LIBRARIES
|
||||
Qt::CorePrivate
|
||||
Qt::TestPrivate
|
||||
)
|
||||
|
||||
qt_internal_extend_target(tst_qfuture CONDITION MSVC
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include <private/qobject_p.h>
|
||||
|
||||
#include <QTest>
|
||||
#include <QtTest/private/qcomparisontesthelper_p.h>
|
||||
#include <qfuture.h>
|
||||
#include <qfuturewatcher.h>
|
||||
#include <qresultstore.h>
|
||||
@ -161,6 +162,7 @@ class tst_QFuture: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
void compareCompiles();
|
||||
void resultStore();
|
||||
void future();
|
||||
void futureToVoid();
|
||||
@ -273,6 +275,12 @@ private:
|
||||
QtPrivate::ResultStoreBase &store;
|
||||
};
|
||||
|
||||
void tst_QFuture::compareCompiles()
|
||||
{
|
||||
QTestPrivate::testEqualityOperatorsCompile<QFuture<int>::const_iterator>();
|
||||
QTestPrivate::testEqualityOperatorsCompile<QFuture<QString>::const_iterator>();
|
||||
}
|
||||
|
||||
void tst_QFuture::resultStore()
|
||||
{
|
||||
int int0 = 0;
|
||||
@ -1359,16 +1367,16 @@ void tst_QFuture::iterators()
|
||||
QFuture<int>::const_iterator i1 = f.begin(), i2 = i1 + 1;
|
||||
QFuture<int>::const_iterator c1 = i1, c2 = c1 + 1;
|
||||
|
||||
QCOMPARE(i1, i1);
|
||||
QCOMPARE(i1, c1);
|
||||
QCOMPARE(c1, i1);
|
||||
QCOMPARE(c1, c1);
|
||||
QCOMPARE(i2, i2);
|
||||
QCOMPARE(i2, c2);
|
||||
QCOMPARE(c2, i2);
|
||||
QCOMPARE(c2, c2);
|
||||
QCOMPARE(1 + i1, i1 + 1);
|
||||
QCOMPARE(1 + c1, c1 + 1);
|
||||
QT_TEST_EQUALITY_OPS(i1, i1, true);
|
||||
QT_TEST_EQUALITY_OPS(i1, c1, true);
|
||||
QT_TEST_EQUALITY_OPS(c1, i1, true);
|
||||
QT_TEST_EQUALITY_OPS(c1, c1, true);
|
||||
QT_TEST_EQUALITY_OPS(i2, i2, true);
|
||||
QT_TEST_EQUALITY_OPS(i2, c2, true);
|
||||
QT_TEST_EQUALITY_OPS(c2, i2, true);
|
||||
QT_TEST_EQUALITY_OPS(c2, c2, true);
|
||||
QT_TEST_EQUALITY_OPS(1 + i1, i1 + 1, true);
|
||||
QT_TEST_EQUALITY_OPS(1 + c1, c1 + 1, true);
|
||||
|
||||
QVERIFY(i1 != i2);
|
||||
QVERIFY(i1 != c2);
|
||||
|
Loading…
x
Reference in New Issue
Block a user