diff options
author | Tatiana Borisova <tatiana.borisova@qt.io> | 2024-04-23 14:29:36 +0200 |
---|---|---|
committer | Tatiana Borisova <tatiana.borisova@qt.io> | 2024-05-08 22:05:35 +0200 |
commit | ec88e63f2a321ec010a7cbc5e5f48b22533a4c40 (patch) | |
tree | 1a005b4305ab41aa30468dcc947c6cfedfe53ac5 | |
parent | 5ea248155654b58fcb52ef326dc4d94de83d0409 (diff) |
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>
-rw-r--r-- | src/corelib/thread/qfuture.h | 8 | ||||
-rw-r--r-- | src/corelib/thread/qfuture.qdoc | 8 | ||||
-rw-r--r-- | tests/auto/corelib/thread/qfuture/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/auto/corelib/thread/qfuture/tst_qfuture.cpp | 28 |
4 files changed, 29 insertions, 16 deletions
diff --git a/src/corelib/thread/qfuture.h b/src/corelib/thread/qfuture.h index 5939a93780..3945df066a 100644 --- a/src/corelib/thread/qfuture.h +++ b/src/corelib/thread/qfuture.h @@ -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 diff --git a/src/corelib/thread/qfuture.qdoc b/src/corelib/thread/qfuture.qdoc index 9eda766968..b278d39882 100644 --- a/src/corelib/thread/qfuture.qdoc +++ b/src/corelib/thread/qfuture.qdoc @@ -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!=() diff --git a/tests/auto/corelib/thread/qfuture/CMakeLists.txt b/tests/auto/corelib/thread/qfuture/CMakeLists.txt index aa989f3df1..ba5730d5cf 100644 --- a/tests/auto/corelib/thread/qfuture/CMakeLists.txt +++ b/tests/auto/corelib/thread/qfuture/CMakeLists.txt @@ -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 diff --git a/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp b/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp index 3fc796514d..4cb29c514a 100644 --- a/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp +++ b/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp @@ -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); |