From edc953948c814c0729d9e22ac903343d4cead0cc Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 10 May 2023 20:07:49 +0200 Subject: 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 --- .../corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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; } -- cgit v1.2.3