Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Chapter 11. Boost.Lambda

Jaakko Jrvi

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(lambda 表達式簡介)
Using the library(庫的使用)
Introductory Examples(介紹性示例)
Parameter and return types of lambda functors(lambda 仿函數的參數和返回類型)
About actual arguments to lambda functors(關於 lambda 仿函數的實際參數)
Storing bound arguments in lambda functions(在 lambda 函數中存儲已綁定參數)
Lambda expressions in details(lambda 表達式詳細研究)
Placeholders(佔位符)
Operator expressions(操作符表達式)
Bind expressions(bind 表達式)
Overriding the deduced return type(越過推演出的返回類型)
Delaying constants and variables(延遲常量和變量)
Lambda expressions for control structures(控制結構的 lambda 表達式)
Exceptions(異常)
Construction and destruction(構造函數和析構函數)
Special lambda expressions(特殊lambda 表達式)
Casts, sizeof and typeid(強制轉型,sizeof 和 typeid)
Nesting STL algorithm invocations(嵌入 STL 算法調用)
Extending return type deduction system(擴展返回類型推演系統)
Practical considerations(實踐中的考慮)
Performance(性能)
About compiling(關於編譯)
Portability(可移植性)
Relation to other Boost libraries(和其它 Boost 庫的關係)
Boost Function
Boost Bind
Contributors(貢獻者)
A. Rationale for some of the design decisions(某些設計權衡的根本原因)
Lambda functor arity(lambda 仿函數數量)
Bibliography 參考資料

In a nutshell

Boost Lambda Library(簡稱為 BLL)是一個 C++ 模板庫,為 C++ 實現了 lambda abstractions 的形式。這個術語起源於函數式編程和 lambda 演算,一個 lambda abstraction 定義一個無名函數。BLL 的主要動機是為定義供 STL 算法使用的無名函數對像提供靈活性和便利性。在講解一個庫是什麼的時候,一行代碼往往勝過千言萬語,下面這一行輸出以空格分隔的某個 STL 容器 a 中的元素:

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

表達式 std::cout << _1 << ' ' 定義了一個一元的函數對象。變量 _1 是這個函數的形式參數,相當於一個實際參數的 placeholder(佔位符)。在 for_each 的每一次迭代中,針對實際參數 a 中的元素調用這個函數。這個實際參數取代了佔位符,而這個函數體被求值。

BLL 的本質是讓你就像上面那個一樣,在緊挨著 STL 算法調用位置的上面,定義小的無名函數對象。

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.

[Jr99] Lecture Notes in Computer Science. 1977. Springer. 2000.

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

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

[Jr03] 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 29, 2006 at 19:28:48 GMT


PrevUpHomeNext