From 8c49ae522d184deb5a9118ba2368629709ff6e85 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 12 Jul 2021 10:10:38 +0200 Subject: QDuplicateTracker: bring back appendTo() && MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit c19695ab953c979f15bbc72c4f4a453e9a114cf6. Just because QSet has limited API doesn't mean we can't provide this in an efficient way for std::unordered_set :P Added tests. Pick-to: 6.2 Change-Id: I4f8f0e60c810acdc666cf34f929845227ed87f3b Reviewed-by: MÃ¥rten Nordheim Reviewed-by: Lars Knoll --- .../qduplicatetracker/tst_qduplicatetracker.cpp | 44 ++++++++++++++++++---- 1 file changed, 37 insertions(+), 7 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/corelib/tools/qduplicatetracker/tst_qduplicatetracker.cpp b/tests/auto/corelib/tools/qduplicatetracker/tst_qduplicatetracker.cpp index 6462ef0dd7..12a4103060 100644 --- a/tests/auto/corelib/tools/qduplicatetracker/tst_qduplicatetracker.cpp +++ b/tests/auto/corelib/tools/qduplicatetracker/tst_qduplicatetracker.cpp @@ -94,9 +94,15 @@ void tst_QDuplicateTracker::appendTo() QVERIFY(!tracker.hasSeen(2)); QList c; - tracker.appendTo(c); + std::move(tracker).appendTo(c); std::sort(c.begin(), c.end()); QCOMPARE(c, QList({ 0, 1, 2 })); + if (QDuplicateTracker::uses_pmr) { + // the following is only true if we use the std container + QVERIFY(!tracker.hasSeen(0)); + QVERIFY(!tracker.hasSeen(1)); + QVERIFY(!tracker.hasSeen(2)); + } } struct ConstructionCounted @@ -172,12 +178,36 @@ void tst_QDuplicateTracker::appendTo_special() QVERIFY(!tracker.hasSeen(1)); QVERIFY(!tracker.hasSeen(2)); QVERIFY(!tracker.hasSeen(3)); - QList a; - a.reserve(3); - tracker.appendTo(a); - for (const auto &counter : a) { - QCOMPARE(counter.moves, 1); - QCOMPARE(counter.copies, 1); + + QVERIFY(tracker.hasSeen(1)); + QVERIFY(tracker.hasSeen(2)); + QVERIFY(tracker.hasSeen(3)); + { + QList a; + a.reserve(3); + tracker.appendTo(a); + for (const auto &counter : a) { + QCOMPARE(counter.moves, 1); + QCOMPARE(counter.copies, 1); + } + } + QVERIFY(tracker.hasSeen(1)); + QVERIFY(tracker.hasSeen(2)); + QVERIFY(tracker.hasSeen(3)); + { + QList a; + a.reserve(3); + std::move(tracker).appendTo(a); + if (QDuplicateTracker::uses_pmr) { + // the following is only true if we use the std container + for (const auto &counter : a) { + QCOMPARE(counter.moves, 2); + QCOMPARE(counter.copies, 0); + } + QVERIFY(!tracker.hasSeen(1)); + QVERIFY(!tracker.hasSeen(2)); + QVERIFY(!tracker.hasSeen(3)); + } } } -- cgit v1.2.3