tst_QSet: check whether QSet::removeIf() can modify elements

It can't, pfew. Was wondering for a moment, but of course, even the
QSet::iterator is really a const_iterator.

Pick-to: 6.8 6.5 6.2
Change-Id: I85caa64c1caca6d77569aa2ceb868a4aa0e5578d
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Reviewed-by: Magdalena Stojek <magdalena.stojek@qt.io>
Reviewed-by: Lena Biliaieva <lena.biliaieva@qt.io>
(cherry picked from commit a4fd95c51a4347482d6d0a815657d0b5bdaf06db)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2025-01-17 16:11:21 +01:00 committed by Qt Cherry-pick Bot
parent ad014ed702
commit 9120bb9e03

View File

@ -33,6 +33,7 @@ private slots:
void cpp17ctad();
void remove();
void removeOnlyDetachesIfSomethingGetsRemoved();
void removeIfDoesNotAllowThePredicateToModifyTheElement();
void contains();
void containsSet();
void begin();
@ -424,6 +425,17 @@ void tst_QSet::removeOnlyDetachesIfSomethingGetsRemoved()
QVERIFY(copy.isDetached());
}
void tst_QSet::removeIfDoesNotAllowThePredicateToModifyTheElement()
{
QSet<int> set = {0, 1, 2, 3};
set.removeIf([](auto &&e) {
if constexpr (!std::is_const_v<std::remove_reference_t<decltype(e)>>)
e *= 2;
return false;
});
QCOMPARE(set, QSet({0, 1, 2, 3}));
}
void tst_QSet::contains()
{
QSet<QString> set1;