在这个例子中,如果我用 bind 改变这个调用:
boost::asio::async_connect(
socket_,
results.begin(),
results.end(),
std::bind(
&session::on_connect,
shared_from_this(),
std::placeholders::_1));
对此:
auto self = shared_from_this();
boost::asio::async_connect(
socket_,
results.begin(),
results.end(),
[self](boost::system::error_code ec) {
self->on_connect(ec);
});
我收到一个断言错误:
boost/boost/asio/impl/connect.hpp:761: error: static_assert failed "IteratorConnectHandler type requirements not met"
BOOST_ASIO_ITERATOR_CONNECT_HANDLER_CHECK(
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
那里有一条评论:
// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a IteratorConnectHandler.
我个人不喜欢 bind,想把它改成 lambda。我做错了吗,或者这是 boost::beast 中的一个小错误?
顺便说一句,更改为 lambda foron_resolve
工作正常。