Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

Chapter 18. Boost.Lambda

Jaakko Järvi

Use, modification and distribution is subject to the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

Table of Contents

In a nutshell
Getting Started
Installing the library
Conventions used in this document
Introduction
Motivation
Introduction to lambda expressions
Using the library
Introductory Examples
Parameter and return types of lambda functors
About actual arguments to lambda functors
Storing bound arguments in lambda functions
Lambda expressions in details
Placeholders
Operator expressions
Bind expressions
Overriding the deduced return type
Delaying constants and variables
Lambda expressions for control structures
Exceptions
Construction and destruction
Special lambda expressions
Casts, sizeof and typeid
Nesting STL algorithm invocations
Extending return type deduction system
Practical considerations
Performance
About compiling
Portability
Relation to other Boost libraries
Boost Function
Boost Bind
Contributors
Rationale for some of the design decisions
Lambda functor arity
Bibliography

In a nutshell

The Boost Lambda Library (BLL in the sequel) is a C++ template library, which implements a form of lambda abstractions for C++. The term originates from functional programming and lambda calculus, where a lambda abstraction defines an unnamed function. The primary motivation for the BLL is to provide flexible and convenient means to define unnamed function objects for STL algorithms. In explaining what the library is about, a line of code says more than a thousand words; the following line outputs the elements of some STL container a separated by spaces:

for_each(a.begin(), a.end(), std::cout << _1 << ' ');

The expression std::cout << _1 << ' ' defines a unary function object. The variable _1 is the parameter of this function, a placeholder for the actual argument. Within each iteration of for_each, the function is called with an element of a as the actual argument. This actual argument is substituted for the placeholder, and the body of the function is evaluated.

The essence of BLL is letting you define small unnamed function objects, such as the one above, directly on the call site of an STL algorithm.

Bibliography

[STL94] A. A. Stepanov and M. Lee. The Standard Template Library. Hewlett-Packard Laboratories. 1994. www.hpl.hp.com/techreports .

[SGI02] The SGI Standard Template Library. 2002. www.boost.org/sgi/stl/.

[C++98] International Standard, Programming Languages – C++. ISO/IEC:14882. 1998.

[Jär99] Lecture Notes in Computer Science. 1977. Springer. 2000.

[Jär00] Jaakko Järvi. Gary Powell. The Lambda Library : Lambda Abstraction in C++. Turku Centre for Computer Science. Technical Report . 378. 2000. www.tucs.fi/publications.

[Jär01] Jaakko Järvi. Gary Powell. The Lambda Library : Lambda Abstraction in C++. Second Workshop on C++ Template Programming. Tampa Bay, OOPSLA'01. . 2001. www.oonumerics.org/tmpw01/.

[Jär03] Software - Practice and Expreience. 33:259-291. 2003.

[tuple] The Boost Tuple Library. www.boost.org/libs/tuple/doc/tuple_users_guide.html . 2002.

[type_traits] The Boost type_traits. www.boost.org/libs/type_traits/ . 2002.

[ref] Boost ref. www.boost.org/libs/bind/ref.html . 2002.

[bind] Boost Bind Library. www.boost.org/libs/bind/bind.html . 2002.

[function] Boost Function Library. www.boost.org/libs/function/ . 2002.

[fc++] The FC++ library: Functional Programming in C++. Yannis Smaragdakis. Brian McNamara. yanniss.github.io/fc++/ . 2002.


PrevUpHomeNext