boost::bind和boost::lambda::bind有啥区别?

BlueprintIrene 2010-10-05 10:50:49
RT
谢谢
...全文
361 5 打赏 收藏 转发到动态 举报
写回复
用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?
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
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 hzjboost 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
市面上见的唯一的介绍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.



64,637

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧