除了其他答案中引用的几个差异之外,还有另外两个差异:
-
boost::bind 似乎在某些情况下处理重载的函数名称,而 std::bind 并没有以相同的方式处理它们。见c++11 faq
(使用 gcc 4.7.2,boost lib 版本 1_54)
void foo(){}
void foo(int i){}
auto badstd1 = std::bind(foo);
//compile error: no matching function for call to bind(<unresolved overloaded function type>)
auto badstd2 = std::bind(foo, 1);
//compile error: no matching function for call to bind(<unresolved overloaded function type>)
auto std1 = std::bind(static_cast<void(*)()>(foo)); //compiles ok
auto std2 = std::bind(static_cast<void(*)(int)>(foo), 1); //compiles ok
auto boost1 = boost::bind(foo, 1); //compiles ok
auto boost2 = boost::bind(foo); //compiles ok
因此,如果您只是将所有 boost::bind 替换为 std::bind,您的构建可能会中断。
-
std::bind 可以无缝绑定到 c++11 lambda 类型,而从 boost 1.54 开始的 boost::bind 似乎需要用户输入(除非定义了 return_type)。见boost doc
(使用 gcc 4.7.2,boost lib 版本 1_54)
auto fun = [](int i) { return i;};
auto stdbound = std::bind(fun, std::placeholders::_1);
stdbound(1);
auto boostboundNaive = boost::bind(fun, _1); //compile error.
// error: no type named ‘result_type’ ...
auto boostbound1 = boost::bind<int>(fun, _1); //ok
boostbound1(1);
auto boostbound2 = boost::bind(boost::type<int>(), fun, _1); //ok
boostbound2(1);
因此,如果您只是将所有 std::bind 替换为 boost::bind,您的构建也可能会中断。