summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2023-05-10 20:07:49 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-05-13 18:05:21 +0000
commit82d12a627fcd3c0aba11e5eaaa9684b551971d9f (patch)
tree716513cc9691517502b9e67109cf73f248e72cf4 /tests
parent235f018af721c3ae39c1292fc71c5d76afa81c71 (diff)
tst_ContainerApiSymmetry: fix mutable lambda anti-pattern
STL algorithms, in general, don't specify how often the function objects passed to them are copied during the run of the algorithm. While generate_n is above any reasonable suspicion of copying the function object after the first invocation, passing a mutable lambda containing the counter is still an anti-pattern we don't want people to copy. Fix in the usual way, by keeping the counter external to the lambda. As a drive-by, replace post- with pre-increment. Amends dc091e74431acbe66ae7921ba82d3eb34ae8cc55. Change-Id: I9c44e769fd41e5f7157179a2be4c3534424cf913 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> (cherry picked from commit edc953948c814c0729d9e22ac903343d4cead0cc) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp b/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp
index c3a56b68ec..0c92801ac5 100644
--- a/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp
+++ b/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp
@@ -710,7 +710,8 @@ Container make(int size)
Container c;
c.reserve(size);
using V = typename Container::value_type;
- std::generate_n(std::inserter(c, c.end()), size, [i = 1]() mutable { return V(i++); });
+ int i = 0;
+ std::generate_n(std::inserter(c, c.end()), size, [&i] { return V(++i); });
return c;
}