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

Click here to view the latest version of this page.

C++ BOOST The Boost Lambda Library

The Boost Lambda Library is free software; Permission to copy, use, modify and distribute this software and its documentation is granted, provided this copyright notice appears in all copies.


Table of Contents

1. In a nutshell
2. Getting Started
2.1. Installing the library
2.2. Conventions used in this document
3. Introduction
3.1. Motivation
3.2. Introduction to lambda expressions
4. Using the library
4.1. Introductory Examples
4.2. Parameter and return types of lambda functors
4.3. About actual arguments to lambda functors
4.4. Storing bound arguments in lambda functions
5. Lambda expressions in details
5.1. Placeholders
5.2. Operator expressions
5.3. Bind expressions
5.4. Overriding the deduced return type
5.5. Delaying constants and variables
5.6. Lambda expressions for control structures
5.7. Exceptions
5.8. Construction and destruction
5.9. Special lambda expressions
5.10. Casts, sizeof and typeid
5.11. Nesting STL algorithm invocations
6. Extending return type deduction system
7. Practical considerations
7.1. Performance
7.2. About compiling
7.3. Portability
8. Relation to other Boost libraries
8.1. Boost Function
8.2. Boost Bind
9. Contributors
A. Rationale for some of the design decisions
1. Lambda functor arity
Bibliography
Documentation as a one big HTML-file

1. In a nutshell

The Boost Lambda Library (BLL in the sequel) is a C++ template library, which implements 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.