Back to Basics: Lambdas from Scratch - Arthur O'Dwyer - CppCon 2019

preview_player
Показать описание



Lambdas — even C++14's mysterious "generic lambdas" — are just syntactic sugar atop constructs that are perfectly understandable when approached from the right direction.

We'll start with the implementation of C-style functions, then move to overloading, function templates, non-static member functions, C++11 lambdas, and then demystify C++14's generic lambdas. We'll cover the minor changes to lambdas in C++17, such as the ability to capture `*this` by value, and indicate some of the minor changes coming in C++2a. Finally, we'll detour into the implementations of std::function and std::bind to show how they're different from lambdas.

Attendees will leave this session with a clear understanding of how C++ — a language without dynamic typing or garbage collection — can nevertheless support efficient lambda closures.

Arthur O'Dwyer
New York

Arthur O'Dwyer is the author of "Colossal Cave: The Board Game," "Mastering the C++17 STL" (the book), and "The STL From Scratch" (the training course). He runs professional C++ training courses, is occasionally active on the C++ Standards Committee, and has a blog mostly about C++.


*-----*
*-----*
Рекомендации по теме
Комментарии
Автор

Thanks so much for the back to basics series! As a beginner, it has helped me immensely in learning C++. I especially love Arthur’s talks!

ZhaoWeiLiew
Автор

31:45 C++ in a nutshell: "... and we can collapse it all down and replace it with one pair of every kind of brackets, and we get something called a generic lambda. Notice that our template parameter T has disappeared, and instead I'm just writing "auto". This is special syntactic sugar, this is not necessarily obvious but "auto" has something to do with type deduction, type inference. So here, when I write "auto" in the parenthesis, it's not the same "auto" that you would see somewhere else ... This is just a shorthand indicating that this lambda's call operator that takes an argument named "x" is actually a template." 😂😭

ChrisOffner
Автор

This is an EXTREMELY good talk. What an absolute legend

alexkfridges
Автор

As a embedded C programmer, I find it is very interesting. Great effort to reduce the size of code segment. But I feel intimidated by the varity and vastness of coding syntax to remember in C++. C syntaxes are still very small and easy to remember. I am not sure if it is only me feeling this way.

bhaskyOld
Автор

finally a clear and concise explanation

edinetgrunhed
Автор

Nicely explained, especially for c programmers. Clear and simple way to understand lambdas.

asifrizwan
Автор

At 22:30 I understand the eye rolls some emit when they hear others say "Aren't lambdas just new syntax for function pointers?" -- maybe approximately if no captures take place, otherwise, no.

jvsnyc
Автор

crisp.. no nonsense... just what is required to know lambda.

harishvk
Автор

great talk, finally somewhat understanding lambdas. thank you!

dayumnson
Автор

Awesome talk !! good explaining, very clear

idanbismut
Автор

Question - why Recursive Lambdas was left out ?
Another excellent talk Arthur. I have been using Plusme analogy whenever I get stuck

raviayyagari
Автор

Wow! Thanks a lot! Now I understand lambdas.

tysontakayushi
Автор

they seem quite useful but incredibly hard to read or interpret sometimes.

jonnyabatti
Автор

23:25 This explains well, why I abhor implicit conversion in C++.

kamilziemian
Автор

20:30 Why this code is written using stdio.h and printf, that are taken stright from C?

kamilziemian
Автор

Are people really expected to be able to write code with all this syntactic/semantic complexity ?
How many years are they expected to study C++ before they can do anything?

heater
Автор

11:35 As person whoes learn lambdas in Lisp, when I hear something like "Lambda is conceptualy like instance of the class" I cringe.

kamilziemian
Автор

0:15 could someone please share the feedback site? I can't see it in the description. Thank you!

milan_shah
Автор

Errata @22:01 . The code shown at 22:01 is ill-formed.

anoopsrana
Автор

At 39:00, you mention [this, &] and [this, =], but it does not compile on a recent gcc compiler (11)

pruibiebehastoet