Welcome to this bonus section for the course.
In this section, we'll learn the basics of C++ 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 functions.
You may remember that I spoke about functions in the algorithm's lecture in the standard template library
section of the course.
Why is it important to understand functional objects?
Well, because behind the scenes, the C++ compiler generates anonymous or unnamed functional objects
from land expressions.
Then we'll look at the syntax of a lambda expression and go through every part of it.
Well, 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.
Well 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 lambdas 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
lambdas to and from functions.
So let's see what motivated C++ Lambda expressions in the next video.