QtPrivate::ResultIteratorBase: use modernize comparisons

Replace class operators operator==(), operator!=() of
QtPrivate::ResultIteratorBase to friend method comparesEqual() and
Q_DECLARE_EQUALITY_COMPARABLE macro.

Use QT_CORE_REMOVED_SINCE and removed_api.cpp to get rid of
current comparison methods and replace them with a friend.

Task-number: QTBUG-120304
Change-Id: Ib9a50a400df86d1dc034d2a0cfee804109a2b93f
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
bb10
Tatiana Borisova 2024-04-23 15:16:40 +02:00
parent 6688b8eaff
commit ed71387d1c
5 changed files with 45 additions and 22 deletions

View File

@ -1085,6 +1085,20 @@ bool QRegularExpression::operator==(const QRegularExpression &other) const
}
#endif // QT_CONFIG(regularexpression)
#if QT_CONFIG(future)
#include "qresultstore.h"
bool QtPrivate::ResultIteratorBase::operator==(const QtPrivate::ResultIteratorBase &other) const
{
return comparesEqual(*this, other);
}
bool QtPrivate::ResultIteratorBase::operator!=(const QtPrivate::ResultIteratorBase &other) const
{
return !comparesEqual(*this, other);
}
#endif // QT_CONFIG(future)
#include "qstring.h" // inlined API
#if QT_CONFIG(thread)

View File

@ -88,16 +88,6 @@ void ResultIteratorBase::batchedAdvance()
m_vectorIndex = 0;
}
bool ResultIteratorBase::operator==(const ResultIteratorBase &other) const
{
return (mapIterator == other.mapIterator && m_vectorIndex == other.m_vectorIndex);
}
bool ResultIteratorBase::operator!=(const ResultIteratorBase &other) const
{
return !operator==(other);
}
bool ResultIteratorBase::isVector() const
{
return mapIterator.value().isVector();

View File

@ -46,12 +46,21 @@ public:
ResultIteratorBase operator++();
int batchSize() const;
void batchedAdvance();
#if QT_CORE_REMOVED_SINCE(6, 8)
bool operator==(const ResultIteratorBase &other) const;
bool operator!=(const ResultIteratorBase &other) const;
#endif
bool isVector() const;
bool canIncrementVectorIndex() const;
bool isValid() const;
private:
friend bool comparesEqual(const ResultIteratorBase &lhs,
const ResultIteratorBase &rhs) noexcept
{
return (lhs.mapIterator == rhs.mapIterator && lhs.m_vectorIndex == rhs.m_vectorIndex);
}
Q_DECLARE_EQUALITY_COMPARABLE(ResultIteratorBase)
protected:
QMap<int, ResultItem>::const_iterator mapIterator;
int m_vectorIndex;

View File

@ -16,4 +16,5 @@ qt_internal_add_test(tst_qresultstore
tst_qresultstore.cpp
LIBRARIES
Qt::CorePrivate
Qt::TestPrivate
)

View File

@ -2,7 +2,7 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QtTest/private/qcomparisontesthelper_p.h>
#include <qresultstore.h>
using namespace QtPrivate;
@ -23,6 +23,7 @@ class tst_QtConcurrentResultStore : public QObject
public slots:
void init();
private slots:
void compareCompiles();
void construction();
void iterators();
void addResult();
@ -52,6 +53,11 @@ void tst_QtConcurrentResultStore::init()
vec1 = QList<int> { 4, 5 };
}
void tst_QtConcurrentResultStore::compareCompiles()
{
QTestPrivate::testEqualityOperatorsCompile<ResultIteratorBase>();
}
void tst_QtConcurrentResultStore::construction()
{
ResultStoreBase store;
@ -74,17 +80,20 @@ void tst_QtConcurrentResultStore::iterators()
storebase.addResult(1, &int1); // ResultStoreBase does not take ownership, only ResultStore<> does.
ResultIteratorBase it = storebase.begin();
QCOMPARE(it.resultIndex(), 0);
QCOMPARE(it, storebase.begin());
QT_TEST_EQUALITY_OPS(it, storebase.begin(), true);
QVERIFY(it != storebase.end());
++it;
QCOMPARE(it.resultIndex(), 1);
QVERIFY(it != storebase.begin());
QVERIFY(it != storebase.end());
QT_TEST_EQUALITY_OPS(it, storebase.begin(), false);
QT_TEST_EQUALITY_OPS(it, storebase.end(), false);
++it;
QVERIFY(it != storebase.begin());
QCOMPARE(it, storebase.end());
QT_TEST_EQUALITY_OPS(it, storebase.end(), true);
}
}
@ -147,8 +156,8 @@ void tst_QtConcurrentResultStore::addResults()
store.addResults(-1, &vec1);
ResultIteratorBase it = store.begin();
QCOMPARE(it.resultIndex(), 0);
QCOMPARE(it, store.begin());
QVERIFY(it != store.end());
QT_TEST_EQUALITY_OPS(it, store.begin(), true);
QT_TEST_EQUALITY_OPS(it, store.end(), false);
++it;
QCOMPARE(it.resultIndex(), 1);
@ -162,7 +171,7 @@ void tst_QtConcurrentResultStore::addResults()
QCOMPARE(it.resultIndex(), 3);
++it;
QCOMPARE(it, store.end());
QT_TEST_EQUALITY_OPS(it, store.end(), true);
QList<int> empty;
const auto countBefore = store.count();
@ -184,22 +193,22 @@ void tst_QtConcurrentResultStore::resultIndex()
ResultIteratorBase it = store.begin();
QCOMPARE(it.resultIndex(), 0);
QVERIFY(it == store.begin());
QVERIFY(it != store.end());
QT_TEST_EQUALITY_OPS(it, store.begin(), true);
QT_TEST_EQUALITY_OPS(it, store.end(), false);
++it;
QCOMPARE(it.resultIndex(), 1);
QVERIFY(it != store.begin());
QVERIFY(it != store.end());
QT_TEST_EQUALITY_OPS(it, store.begin(), false);
QT_TEST_EQUALITY_OPS(it, store.end(), false);
++it;
QCOMPARE(it.resultIndex(), 2);
QVERIFY(it != store.end());
QT_TEST_EQUALITY_OPS(it, store.end(), false);
++it;
QCOMPARE(it.resultIndex(), 3);
QVERIFY(it != store.end());
QT_TEST_EQUALITY_OPS(it, store.end(), false);
++it;
QVERIFY(it == store.end());
QT_TEST_EQUALITY_OPS(it, store.end(), true);
QCOMPARE(store.resultAt(0).value<int>(), int0);
QCOMPARE(store.resultAt(1).value<int>(), vec0[0]);