[英]Should I be seeing significant differences between std::bind and boost::bind?
I'm exploring the support for C++11 on the g++-4.7 (Ubuntu/Linaro 4.7.3-2ubuntu~12.04, to be specific) and I seem to be finding differences. 我正在探索对g ++ - 4.7(Ubuntu / Linaro 4.7.3-2ubuntu~12.04,具体而言)对C ++ 11的支持,我似乎发现了差异。
In particular, if I comment out #include <boost/bind.hpp>
and systematically replace occurrences of boost::bind
with std::bind
in the Boost ASIO async client example (taken from http://www.boost.org/doc/libs/1_45_0/doc/html/boost_asio/example/http/client/async_client.cpp ), the program no longer compiles. 特别是,如果我注释掉
#include <boost/bind.hpp>
并在Boost ASIO异步客户端示例中系统地用std::bind
替换boost::bind
出现(取自http://www.boost.org/) doc / libs / 1_45_0 / doc / html / boost_asio / example / http / client / async_client.cpp ),程序不再编译。
Any explanation for this? 对此有何解释?
#include <functional>
namespace boost {
namespace asio {
namespace stdplaceholders {
static decltype ( :: std :: placeholders :: _1 ) & error = :: std :: placeholders :: _1;
static decltype ( :: std :: placeholders :: _2 ) & bytes_transferred = :: std :: placeholders :: _2;
static decltype ( :: std :: placeholders :: _2 ) & iterator = :: std :: placeholders :: _2;
static decltype ( :: std :: placeholders :: _2 ) & signal_number = :: std :: placeholders :: _2;
}
}
}
and use boost::asio::stdplaceholders::*
instead of boost::asio::placeholders::*
并使用
boost::asio::stdplaceholders::*
而不是boost::asio::placeholders::*
It looks like boost::asio::placeholders
cannot be used in conjunction with std::bind
. 看起来像
boost::asio::placeholders
不能与std::bind
一起使用。 In the example you've linked to, the first call to boost::bind
occurs in the following code: 在您链接的示例中,第一次调用
boost::bind
发生在以下代码中:
resolver_.async_resolve(query,
boost::bind(&client::handle_resolve, this,
boost::asio::placeholders::error,
boost::asio::placeholders::iterator));
Simply replacing boost::bind
with std::bind
leads to a bunch of errors. 简单地用
std::bind
替换boost::bind
会导致一堆错误。 To make it compile you need to replace boost::asio::placeholders
with std::placeholders
. 要使其编译,您需要使用
std::placeholders
替换boost::asio::placeholders
std::placeholders
。
resolver_.async_resolve(query,
std::bind(&client::handle_resolve, this,
std::placeholders::_1,
std::placeholders::_2));
Note that I haven't verified that the code is functionally the same after making these changes, only that it compiles. 请注意,在进行这些更改之后,我还没有验证代码在功能上是否相同,只是它编译。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.