CppCon 2015: Arthur O'Dwyer “Lambdas from First Principles: A Whirlwind Tour of C++"”
Why Stack Overflow recommends it
Stack Overflow users link it when answering questions about how lambdas, templates and their static variables actually work under the hood.
Recommended by 3 people across 4 different months, 2016 to 2017.
What it is
A CppCon 2015 talk by Arthur O'Dwyer that builds up C++ lambdas from first principles. It starts with C-style functions and moves through overloading, function templates, member functions and C++11 lambdas, then explains C++14 generic lambdas and how std::function and std::bind differ from lambdas.
What people said
Strong rec Aaron McDaid · 2016-05 · Stack Overflow · on “Generic C++14 lambdas and relationship with templates”
This talk at cppcon 2015 [this video] is very relevant (and good!). *"Lambdas from First Principles: A Whirlwind Tour of C++"*
Recommends 463035818_is_not_an_ai · 2016-06 · Stack Overflow · on “Template function static variable”
This is because an instantiation of a template, once instantiated, has nothing to do with a second instantiation of the same template. The two are seperate entities and get their own static variable. PS: Here is a video where this occurs in an example: CppCon 2015: Arthur O'Dwyer “Lambdas from First Principles: A Whirlwind Tour of C++"” [this video] . The example starts aroung 6:00
Recommends 463035818_is_not_an_ai · 2016-07 · Stack Overflow · on “Type-specific static declaration in a template function”
Note that once instantiated log2<double> and log2<float> are two completely different functions. They both get their own static variable. After template instantiation, this is the same situation as if you had two functions: double log2(double) { static double x; /*...*/ } and float log2(float) { static float x; /*...*/ } This is also nicely explained here [this video] in an example around 6:00.
Recommends Quuxplusone · 2017-09 · Stack Overflow · on “Avoid memory allocation with std::function and member function”
@NirFriedman: Upvoted for agreement. :) @Mehrdad: The lambda's "closure" (its set of captures) *is* just a single pointer, namely, `&cb`. It doesn't need to capture anything else. I have a CppCon talk [this video] on the subject of "how can a lambda be just ___". :)