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 dc091e7443.
Pick-to: 6.5 6.2
Change-Id: I9c44e769fd41e5f7157179a2be4c3534424cf913
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
bb10
parent
3cc39197f8
commit
edc953948c
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue