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.9 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>
This commit is contained in:
parent
768ab20517
commit
a4fd95c51a
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user