Learn how a lambda function may be used in place of the operator function as the final argument to the transform function.
- [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 we notice that its operator is x,…
- Template fundamentals
- STL containers
- Accessing iterators
- Output, forward, and bidirectional iterators
- The transform function
- Transforming strings and types
- Arithmetic, relational, and logical functions
- STL algorithms
Skill Level Intermediate
2. STL Containers
3. STL Iterators
5. STL Functions
6. STL Algorithm
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.