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.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>
(cherry picked from commit 9120bb9e0393bd10e73510d0103bc330f5b92696)
bb10
Marc Mutz 2025-01-17 16:11:21 +01:00 committed by Qt Cherry-pick Bot
parent 0a36fd1978
commit c1825660aa
1 changed files with 12 additions and 0 deletions

View File

@ -30,6 +30,7 @@ private slots:
void cpp17ctad();
void remove();
void removeOnlyDetachesIfSomethingGetsRemoved();
void removeIfDoesNotAllowThePredicateToModifyTheElement();
void contains();
void containsSet();
void begin();
@ -394,6 +395,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;