C++ lambdas are just structs that overload operator(); once you realize that they become a lot less mysterious. But it's a great example of how this tool is useful to learn about those things (of course you could also read the C++ standard but who has time for that?)
(That also shows how C++'s range-based for-loops work, which is similarly some syntactic suger for a fairly mundane for-loop, but details are interesting: unlike a typical for-loop, the loop variable is declared inside the loop body.)
I said shows a lambda _capture_. This involves the compiler automatically determining which variables cross the scope boundary, and injecting code for each one.
C++ lambdas are just structs that overload operator(); once you realize that they become a lot less mysterious. But it's a great example of how this tool is useful to learn about those things (of course you could also read the C++ standard but who has time for that?)
Here's an example: https://cppinsights.io/s/f04b6896
(That also shows how C++'s range-based for-loops work, which is similarly some syntactic suger for a fairly mundane for-loop, but details are interesting: unlike a typical for-loop, the loop variable is declared inside the loop body.)
I said shows a lambda _capture_. This involves the compiler automatically determining which variables cross the scope boundary, and injecting code for each one.
You can see it by typing in the sample code in the tool here - https://news.ycombinator.com/item?id=49928362
I second this.
https://news.ycombinator.com/item?id=49945197
[dead]