|
|
|
|
|
by flohofwoe
3537 days ago
|
|
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). |
|
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.