4 ms·
This is a common mistake in pretty much any language that captures a closure inside a lambda: C++, JS, etc. Unfortunately, debugging this the first time takes 2
by mindfulplay 10y ago
This is a common mistake in pretty much any language that captures a closure inside a lambda: C++, JS, etc. Unfortunately, debugging this the first time takes 20 minutes; the next time, it takes 0 seconds.
- kbwt 10y ago> common mistake in C++ Not really. You have to explicitly specify you want capture-by-reference with C++ lambdas. The code would also look very out-of-place to a C++ programmer, because you would never capture a loop counter by reference if you intend to use the lambda outside of the loop. Lifetimes don't just get magically extended into completely unrelated scopes.