Hacker News new | past | comments | ask | show | jobs | submit login

Not sure I like implicit capture more than explicit capture but there's [=] if you need it. Also, the return value as the article mentions is optional, so most lambdas look like

    const auto nestedfunc = [=](a,b) { /* */ };
Which isn't that much different to me than

    { /* some scope */
        function nestedfunc(a,b) { /* */ }
    }
const and auto are needed but because it's C++. Beyond that, you have an equals sign which is needed here but [=] which is three characters. Again, small differences, not sure why it looks that much worse.



Now that we know lambdas they are fine, but to answer the question "why is there a book" in the beginning of the thread, it is more or less because it is not as obvious as gcc's c extension.


What is so cryptic that there needs to be a separate syntax change?

    auto triple = [](auto x){ return 3 * x; };


Ye well nothing when we have already are to lambdas.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: