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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.