summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2023-05-10 20:07:49 +0200
committerMarc Mutz <marc.mutz@qt.io>2023-05-13 16:58:10 +0200
commitedc953948c814c0729d9e22ac903343d4cead0cc (patch)
treef6bffd2f71bfe47d3356f2cb7608d045aceae5c8 /tests/auto/corelib/tools
parent3cc39197f816ac7a84b5211df23e553309fe44c0 (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. Pick-to: 6.5 6.2 Change-Id: I9c44e769fd41e5f7157179a2be4c3534424cf913 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Diffstat (limited to 'tests/auto/corelib/tools')
-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 c438d6f961..911e2275bb 100644
--- a/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp
+++ b/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp
@@ -720,7 +720,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;
}