logoalt Hacker News

StilesCrisis • today at 2:00 PM • 5 replies • view on HN

I wish the readme example showed a lambda capture. Now that's where compiler magic REALLY shows up.


Replies

sltkr • today at 8:35 PM

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.)

➕ show 1 reply
rramadass • today at 3:37 PM

You can see it by typing in the sample code in the tool here - https://news.ycombinator.com/item?id=49928362

mrlonglong • today at 3:30 PM

I second this.

➕ show 1 reply
WalterBright • today at 5:24 PM

[dead]