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

Title of the research paper should be "C++ is not Haskell", but snark aside, I find C++11 lambdas useful to replace old-school callback code (of course only if callbacks make sense in a situation) because:

- if local variables need to be captured, the code is much less noisy than using the old std::bind mess

- non-capturing lambdas also work for C-style function pointers, and in this case the generated code is very efficient (no std::function object created under the hood)

If you're aware what happens under the hood (...that in most cases a std::function object will be created, which in turn might do a dynamic memory allocation to hold captured variables), lambdas are a useful syntactic sugar and one of the more useful additions in C++11 (IMHO).




I'm pretty sure that most uses of lambda don't involve creation of std::function (and thus dynamic allocation and virtual function calls).

As long as you maintain the distinct type of the lambda, any captures (by reference or by value) will just be fields in a stack object.




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact

Search: