(uplifting music)
-: Welcome to this bonus section for the course.
In this section, we'll learn the basics
of C++ plus Lambda expressions.
Lambda expressions were first introduced in C++ 11,
and then extended in C++ 14 and 17.
They provide a very convenient way
to provide functionality exactly where it's needed
without writing lots and lots of code.
In order to understand Lambda expressions,
it's important to understand what they are
and what motivated their addition to C++.
First, we'll look
at what motivated C++ Lambda expressions,
and in order to do that, we'll quickly review using C++
function objects, or functors.
You may remember that I spoke
about functors in the Algorithms lecture
in the Standard Template Library section of the course.
Why is it important to understand function objects?
Well, because behind the scenes
the C++ compiler generates anonymous
or unnamed functional objects from Lambda expressions.
Then we'll look at the syntax
of a Lambda expression and go through every part of it.
We'll then see the difference
between stateless and stateful Lambda expressions.
Stateless lambdas only know
about the information that's passed into them
via the parameter list, pretty much like a regular function.
We'll then learn about stateful lambdas.
These are a bit more complex
since they can capture the elements
from the environment that they execute in,
so they close around their environment,
and that's where the concept of a closure comes from.
This is a very, very powerful concept
and happens via the Lambda's capture list.
There are lots of options here,
and we'll look at the ones that are most commonly used.
Finally, we'll look at Lambdas in the context of the STL.
We've already seen basic lambdas in the STL section,
but we'll look at a few more examples here.
That's it.
I hope you enjoyed this section.
Please remember, I'm only covering the basics
of C++ Lambda expressions.
They can get very complex when we use them
with templates, as class functions,
and when we pass and return Lambda's to and from functions.
So let's see what motivated C++ Lambda expressions
in the next video.