| Home | Libraries | People | FAQ | More

## Chapter 6. Boost.Lambda

### Jaakko Järvi

`<jarvi at cs tamu edu>`

Copyright © 1999-2004 Jaakko Järvi, Gary Powell

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)

### 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.

## 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.sgi.com/tech/stl/.

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

[Jär99] Jaakko Järvi. C++ Function Object Binders Made Easy. . 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] Jaakko Järvi. Gary Powell. Andrew Lumsdaine. The Lambda Library : unnamed functions in C++. . 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. www.cc.gatech.edu/~yannis/fc++/. 2002.

Last revised: November 28, 2004 at 03:29:16 GMT |