C++ Weekly - Ep 152 - Lambdas: The Key To Understanding C++

preview_player
Показать описание
☟☟ Awesome T-Shirts! Sponsors! Books! ☟☟

T-SHIRTS AVAILABLE!

WANT MORE JASON?

SUPPORT THE CHANNEL

GET INVOLVED

JASON'S BOOKS

► C++23 Best Practices

► C++ Best Practices

JASON'S PUZZLE BOOKS

► Object Lifetime Puzzlers Book 1

► Object Lifetime Puzzlers Book 2

► Object Lifetime Puzzlers Book 3

► Copy and Reference Puzzlers Book 1

► Copy and Reference Puzzlers Book 2

► Copy and Reference Puzzlers Book 3

► OpCode Puzzlers Book 1


RECOMMENDED BOOKS

AWESOME PROJECTS

O'Reilly VIDEOS

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

Wow! my mind is blown away! absolutely amazing! Thank you Jason 😍

thestarinthesky_
Автор

One more thing is "user-defined conversion functions" because lambda with no captures is implicitly convertible to function pointer type

mikedemchenko
Автор

Such a meme episode. This channel becames a "Lambdas weekly" slowly but surely

Grom
Автор

Def I recommend this channel to my fellow colleagues. Thanks Jason

chandureddy
Автор

Big missing item: member fields; the captures need to be stored somewhere.
Captures are also passed by copy/reference/move, more big concepts important to C++.

randfur
Автор

half of the points is completely orthogonal to lambdas. It's like saying that to understand 'int x = 5' you need to understand variadic templates because it might be actually variadic template variable declaration and classes (because it might be not int but class) and const and volatile and multithreading (because you need to understand how to sync it for multithread access), etc

alexeydmitriev
Автор

To every thing there is a season,
and a time to every purpose under the heaven:
A time for functors, function pointers, and a time for lambdas.

DamianReloaded
Автор

I discovered your channel recently. It is filling so many holes in my poor knowledge of C++, thanks !
And about this particular one, wow, I feel like I slept during one or two dozen years ! I could explain, but I don't think telling you about my life, the universe and the rest would be interesting !...

pandacongolais
Автор

Waiting to see in practice what you mentionned in that list

BloodHaZaRd
Автор

Inline functions are also important. The operator() is defined as inline (3:20) this is the cause why no assembly is generated.

You also need to understand references and copy-initialization to understand the capture of a lambda.

You can also use lambdas for static dispatch; combined with std::integral_constant as a lambda parameter you can enforce the compiler to compile the code as if an integer was constant:


// invoke a lambda expression with a given number n,
// invoke_n is a template function which calls itself
// recursively and tests n against a value in the range
// which is given in the template parameter list
// if n equals to a number, the lambda function is called
// with the parameter n as a std::integral_constant
invoke_n<0, 10>(
n,
[&]<class N>(N) { // n is an instantiation of std::integral_constant
/// use N::value
}
);

cmdlp
Автор

Thanks Jason! The lambda playlist is a must-watch for me :)

hhsaez
Автор

in the past classes were a sink of features, because that was the most flexible part in cpp, now lambdas...

xealit
Автор

To me it seems easier to learn a new language than understand new (post C++03) C++ rules, so I've learned Python and started to learn Scala and get away from C++. Kinda sad, but I don't have the drive to go into this much detail anymore - well, maybe if some great project came along. Good series though :)

krajorama
Автор

Are there still C++ jobs around? What is the starting salary?

deltagamma
Автор

At 2:52 tries to stretch out the video runtime, hiding it with clumsiness. Still missing the 10 minute hurdle :-)

Hauketal
Автор

Bascilly you need to understand the entire C++ before you understand lambdas

abdullahamrsobh
Автор

Lambda's are powerful tools but they can obscure the flow especially when callbacks are overused. Microsoft's Chakra engine is full of it and the flow is hard to follow.

gast
Автор

Kind of missed lifetime from that list. Especially important for captured variables.. Unless that was implied by the "objects" point

jackwhite
Автор

Is there some bracket fetish Bjerne has or what? Is there no other possible variety of characters than brackets to use, it isn't as though they aren't already overly over, over used FFS? Also surely this can be done using normal C++ code?...

infinitesimotel
Автор

I now better understand my intuition as to why lambdas should be avoided.
They are cryptic and complicate and make code hard to reason about. They discourage code reuse. There are very few use cases where lambda is better than plain old functions/classes/templates.

CanIHaveSomeMore