Difference between C++11 std::bind and boost::bind(C++11 std::bind 和 boost::bind 的区别)
问题描述
这两者有什么区别吗?或者我是否可以安全地在我的代码中用 std::bind 替换每次出现的 boost::bind ,从而消除对 Boost 的依赖?
Is there any difference between the two? Or am I safe to replace every occurrence of boost::bind by std::bind in my code and thereby remove the dependence on Boost?
推荐答案
boost::bind有重载关系运算符,std::bind没有.boost::bind支持非默认调用约定,不保证std::bind(标准库实现可能会将此作为扩展提供).boost::bindsupports non-default calling conventions,std::bindis not guaranteed to (standard library implementations may offer this as an extension).boost::bind提供了一种直接机制,允许防止对嵌套绑定表达式(boost::protect),std::bind才不是.(也就是说,如果需要,可以将boost::protect与std::bind一起使用,或者自己简单地重新实现它.)boost::bindprovides a direct mechanism to allow one to prevent eager evaluation of nested bind expressions (boost::protect),std::binddoes not. (That said, one can useboost::protectwithstd::bindif they want, or trivially reimplement it on their own.)std::bind提供了一种直接机制,允许将任何用户定义的函子视为嵌套的绑定表达式,以便强制急切求值(std::is_bind_expression: [func.bind.isbind]/1, [func.bind.bind]/10),boost::bind没有.std::bindprovides a direct mechanism to allow one to treat any user defined functor as a nested bind expression in order to force eager evaluation (std::is_bind_expression: [func.bind.isbind]/1, [func.bind.bind]/10),boost::binddoes not.这篇关于C++11 std::bind 和 boost::bind 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C++11 std::bind 和 boost::bind 的区别
基础教程推荐
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 这个宏可以转换成函数吗? 2022-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
