Boost C++ 库

...世界上评价最高、设计最精巧的 C++ 库项目之一。 Herb SutterAndrei Alexandrescu, C++ Coding Standards

第 17 章。Boost.Lambda - Boost C++ 函数库
PrevUpHomeNext

第 17 章。Boost.Lambda

Jaakko Järvi

使用、修改和分发受 Boost 软件许可证 1.0 版约束。(请参阅随附文件 LICENSE_1_0.txt 或在 https://boost.ac.cn/LICENSE_1_0.txt 复制)

简而言之

Boost Lambda 库(以下简称 BLL)是一个 C++ 模板库,它实现了 C++ 的一种 Lambda 抽象。这个术语源自函数式编程和 Lambda 演算,其中 Lambda 抽象定义了一个无名函数。BLL 的主要目的是为 STL 算法提供灵活方便的方式来定义无名函数对象。在解释这个库的用途时,一行代码胜过千言万语;下面这一行代码将某些 STL 容器 a 的元素用空格分隔输出

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

表达式 std::cout << _1 << ' ' 定义了一个一元函数对象。变量 _1 是这个函数的参数,是实际参数的 占位符。在 for_each 的每次迭代中,该函数都会以 a 的一个元素作为实际参数进行调用。这个实际参数会被替换占位符,然后 函数体 就会被求值。

BLL 的精髓在于允许您在 STL 算法的调用点直接定义上面这样的匿名小函数对象。

参考文献

[STL94] A. A. StepanovM. 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