Lesson 22. C++11 Lambda Expressions

Lambda expressions are a compact way to define and construct function objects without a name. These expressions are new to C++11. In this lesson, you find out

• How to program a lambda expression

• How to use lambda expressions as predicates

• How to program lambda expressions that can hold and manipulate a state

What Is a Lambda Expression?

A lambda expression can be visualized as a compact version of an unnamed struct (or class) with a public operator(). In that sense, a lambda expression is a function object like those in Lesson 21, “Understanding Function Objects.” Before jumping into analyzing the programming of lambda functions, take a function object from Listing 21.1 (from Lesson 21) as an example: ...

Get Sams Teach Yourself C++ in One Hour a Day, Seventh Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.