社区
C++ 语言
帖子详情
boost::bind和boost::lambda::bind有啥区别?
BlueprintIrene
2010-10-05 10:50:49
RT
谢谢
...全文
361
5
打赏
收藏
boost::bind和boost::lambda::bind有啥区别?
RT 谢谢
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
5 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
yshuise
2011-02-19
打赏
举报
回复
“超越c++标准库”上面有讲。我遇到过只能用lambda的情况。
yshuise
2011-02-19
打赏
举报
回复
有时候两个用都可以,有时候只能用lambda::bind
gules
2010-10-06
打赏
举报
回复
boost::bind是标准程序库std::bind1st与std::bind2nd的一般化;
而boost::lambda::bind是一个表达式,用于生成lambda的functor。
细节请查阅boost的文档。
yshuise
2010-10-06
打赏
举报
回复
有lambda那个,显然可以用lambda,比如:
for_each(, , boost::bind(&status::report, _1));
BlueprintIrene
2010-10-06
打赏
举报
回复
我的意思是,在某些情况下,能用boost::lambda::bind的地方也能用boost::bind。比如:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <boost/bind.hpp>
#include <boost/lambda/bind.hpp>
void print(const std::string& prefix, const std::string& text) {
std::cout << prefix << "::" << text << "\n";
}
int main()
{
std::vector<std::string> vec;
vec.push_back("tuple");
vec.push_back("bind");
vec.push_back("lambda");
for_each(vec.begin(), vec.end(), boost::bind(&print, "boost", _1));
for_each(vec.begin(), vec.end(), boost::lambda::bind(&print, "boost", boost::lambda::_1));
}
最后两条语句的输出结果是一样的。
这种时候,用哪个bind好呢?
另外,什么时候该用boost::bind,什么时候该用boost::lambda::bind?
Boost
带领你远远地超越了C++标准库,它使得C++编程更优雅、更有活力、更高产。首先,我们系统地介绍一下
Boost
库的主要组成和它们的主要用法
Björn Karlsson为中级至高级的C++开发者描述了所有58个
Boost
库的轮廓,并完整叙述了12个可能最有用的库。Karlsson的主题范围从智能指针和类型转换,到容器和数据库结构,解释了如何正确地使用每一个库来改进你的代码。他详细论述了可以让你写出更简明、清晰、易读的代码的高级函数对象。他还带你到
Boost
的"幕后",看看那些对你创建自己的泛型库有益的工具和技术。 本书的内容包括: 智能指针,提供自动的对象生存期管理和简单的资源共享 提供类型转换和词汇转换的统一的、最优的解决方案 使编程更简单、更清晰的工具类 灵活的容器类,解决了C++标准库未覆盖的问题 对正则表达式的强有力的支持:
Boost
.Regex 可在调用点进行定义的函数对象:
Boost
.
Bind
和
Boost
.
Lambda
更灵活的回调机制:
Boost
.Function 可管理的信号和响应动作(又称为Observer模式):
Boost
.Signals
THE
BOOST
C++ LIBRARIES
THE
BOOST
C++ LIBRARIES是一份自己编译的chm格式文档,描述了如何使用
boost
类库,目录如下: Front page Chapter 1: Introduction 1.1 C++ and
Boost
1.2 Development Process 1.3 Installation 1.4 Overview Chapter 2: Smart Pointers 2.1 General 2.2 RAII 2.3 Scoped Pointer 2.4 Scoped Array 2.5 Shared Pointer 2.6 Shared Array 2.7 Weak Pointer 2.8 Intrusive Pointer 2.9 Pointer Container 2.10 Exercises Chapter 3: Function Objects 3.1 General 3.2
Boost
.
Bind
3.3
Boost
.Ref 3.4
Boost
.Function 3.5
Boost
.
Lambda
3.6 Exercises Chapter 4: Event Handling 4.1 General 4.2 Signals 4.3 Connections 4.4 Exercises Chapter 5: String Handling 5.1 General 5.2 Locales 5.3
Boost
.StringAlgorithms 5.4
Boost
.Regex 5.5
Boost
.Tokenizer 5.6
Boost
.Format 5.7 Exercises Chapter 6: Multithreading 6.1 General 6.2 Thread Management 6.3 Synchronization 6.4 Thread Local Storage 6.5 Exercises Chapter 7: Asynchronous Input and Output 7.1 General 7.2 I/O Services and I/O Objects 7.3 Scalability and Multithreading 7.4 Network Programming 7.5 Developing
Boost
.Asio Extensions 7.6 Exercises Chapter 8: Interprocess Communication 8.1 General 8.2 Shared Memory 8.3 Managed Shared Memory 8.4 Synchronization 8.5 Exercises Chapter 9: Filesystem 9.1 General 9.2 Paths 9.3 Files and Directories 9.4 File Streams 9.5 Exercises Chapter 10: Date and Time 10.1 General 10.2 Calendar Dates 10.3 Location-independent Times 10.4 Location-dependent Times 10.5 Formatted Input and Output 10.6 Exercises Chapter 11: Serialization 11.1 General 11.2 Archive 11.3 Pointers and references 11.4 Serialization of class hierarchy objects 11.5 Wrapper functions for optimization 11.6 Exercises Chapter 12: Parser 12.1 General 12.2 Extended Backus-Naur Form 12.3 Grammar 12.4 Actions 12.5 Exercises Chapter 13: Containers 13.1 General 13.2
Boost
.Array 13.3
Boost
.Unordered 13.4
Boost
.MultiIndex 13.5
Boost
.Bimap 13.6 Exercises Chapter 14: Data Structures 14.1 General 14.2
Boost
.Tuple 14.3
Boost
.Any 14.4
Boost
.Variant 14.5 Exercises Chapter 15: Error Handling 15.1 General 15.2
Boost
.System 15.3
Boost
.Exception Chapter 16: Cast Operators
C++ function、
bind
以及lamda表达式
本文是C++0x系列的第四篇,主要是内容是C++0x中新增的
lambda
表达式, function对象和
bind
机制。之所以把这三块放在一起讲,是因为这三块之间有着非常密切的关系,通过对比学习,加深对这部分内容的理解。在开始之间,首先要讲一个概念,closure(闭包),这个概念是理解
lambda
的基础。下面我们来看看wikipedia上对于计算机领域的closure的定义: A closure (also lexical closure, function closure or function value) is a function together with a refer
boost
1.41 中文文档,使用帮助,教程手册
1.41.0版本的中文文档20091225,已完成翻译91个库. 汉化
boost
文档,致力
boost
推广。 如果你对本项目有兴趣,欢迎加入,相关说明请查阅项目论坛: https://groups.google.com/ 到目前为止,各人贡献的译文如下: 贡献者 贡献的译文 alai04 accumulators, any, assign, bimap, call_traits, circular_buffer, compatibility, concept check, config, conversion, date_time, filesystem, foreach, function_types, functional, integer, intrusive, io state savers, iostreams, iterators, minmax, mpl, multi_array, multi_index, numeric/conversion, operators, optional, pointer container, pool, preprocessor, program_options, property map, property_tree, proto, range, rational, scope_exit, serialization, spirit, statechart, swap, system, tokenizer, TR1, tribool, unordered, utility, value_initialized, variant, wave, xpressive fatalerror99 array,
bind
& mem_fn, dynamic_bitset, function, functional/hash, in_place_factory & typed_in_place_factory,
lambda
, ref, smart_ptr, static_assert, string_algo, type_traits, typeof farproc compressed_pair, crc, enable_if blackjazz07 conversion/lexical_cast, format hzj
boost
tuple xuwaters parameter, timer 金庆 python, signals, signals2 zhaohongchao exception, gil luckycat06 interval, math, math/complex number algorithms, math/common_factor, math/octonion, math/quaternion, math/special_functions, math/statistical, uBLAS lixin regex, test, units evy.wang thread xiaq random 水的影子 flyweight
Beyond the C++ Standard Library An Introduction to
Boost
市面上见的唯一的介绍
boost
的著作:
Beyond the C++ Standard Library: An Introduction to
Boost
By Björn Karlsson
...............................................
Publisher: Addison Wesley Professional
Pub Date: August 31, 2005
ISBN: 0321133544
Pages: 432
Table of Contents | Index
Introducing the
Boost
libraries: the next breakthrough in C++ programming
Boost
takes you far beyond the C++ Standard Library, making C++ programming more elegant, robust, and productive. Now, for the first time, a leading
Boost
expert systematically introduces the broad set of
Boost
libraries and teaches best practices for their use.
Writing for intermediate-to-advanced C++ developers, Björn Karlsson briefly outlines all 58
Boost
libraries, and then presents comprehensive coverage of 12 libraries you're likely to find especially useful. Karlsson's topics range from smart pointers and conversions to containers and data structures, explaining exactly how using each library can improve your code. He offers detailed coverage of higher-order function objects that enable you to write code that is more concise, expressive, and readable. He even takes you "behind the scenes" with
Boost
, revealing tools and techniques for creating your own generic libraries.
Coverage includes
Smart pointers that provide automatic lifetime management of objects and simplify resource sharing
Consistent, best-practice solutions for performing type conversions and lexical conversions
Utility classes that make programming simpler and clearer
Flexible container libraries that solve common problems not covered by the C++ Standard Library
Powerful support for regular expressions with
Boost
.Regex
Function objects defined at the call site with
Boost
.
Bind
and
Boost
.
Lambda
More flexible callbacks with
Boost
.Function
Managed signals and slots (a.k.a. the Observer pattern) with
Boost
.Signals
The
Boost
libraries are proving so useful that many of them are planned for inclusion in the next version of the C++ Standard Library. Get your head start now, with Beyond the C++ Standard Library.
© Copyright Pearson Education. All rights reserved.
C++ 语言
64,637
社区成员
250,559
社区内容
发帖
与我相关
我的任务
C++ 语言
C++ 语言相关问题讨论,技术干货分享,前沿动态等
复制链接
扫一扫
分享
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++
技术论坛(原bbs)
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
请不要发布与C++技术无关的贴子
请不要发布与技术无关的招聘、广告的帖子
请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下
试试用AI创作助手写篇文章吧
+ 用AI写文章