From the course: C++ Templates and the STL
Unlock this course with a free trial
Join today to access over 22,400 courses taught by industry experts.
Lambda transformations - C++ Tutorial
From the course: C++ Templates and the STL
Lambda transformations
- [Narrator] You may also use a lamba function in place of the functor in your transformations. Here I have a working copy of lambda.cpp from chapter four of the exercise files. For more detail on lambda functions, see the companion course, C++ Advanced Topics, but for now I'm just going to describe the lambda function here. This is a lambda function. Here we're capturing this accum variable, which is an accumulator. It does basically what the class did in our last lesson. It takes one parameter, an integer, called d. And it returns an integer. It's marked as mutable, so the compiler knows that it changes a value. And it simply returns the accumulation, while using the plus-equals operator to accumulate the next value. So, the function itself is pretty simple. This lambda syntax may not be familiar to you, and again see the companion course, C++ Advanced Topics, to learn more about lambda functions. So here we have our transform function which we described in the previous lesson. And…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.