I am trying to adapt one of the boost::asio examples to use c++11 / TR1 libraries where possible. The original code looks like this:
void start_accept()
{
tcp_connection::pointer new_connection =
tcp_connection::create(acceptor_.get_io_service());
acceptor_.async_accept(new_connection->socket(),
boost::bind(&tcp_server::handle_accept, this, new_connection,
boost::asio::placeholders::error));
}
If I replace boost::bind with std::bind as follows:
void start_accept()
{
tcp_connection::pointer new_connection =
tcp_connection::create(acceptor_.get_io_service());
acceptor_.async_accept(new_connection->socket(),
std::bind(&tcp_server::handle_accept, this, new_connection,
boost::asio::placeholders::error ) );
// std::bind(&tcp_server::handle_accept, this, new_connection, _1 ) );
}
I get a large error message, with ends with:
/usr/include/c++/4.4/tr1_impl/functional:1137: error: return-statement with a value, in function returning 'void'
I am using gcc version 4.4 with boost version 1.47
I expected boost::bind and std::bind to be interchangeable.
I now have a solution
The problem is that when I first tried to switch to
std::bindandstd::shared_ptrI was still using theboost::asio::placeholderswithstd::bind, this resulted in a large amount of template compiler errors, so I then tried to switch piecemeal.I first tried switching just
boost::shared_ptrtostd::shared_ptr, this failed becauseboost::bindwill not work withstd::shared_ptrwith out a specialisation of the templateget_pointer<typename T>forstd::shared_ptr(see: How to resolve conflict between boost::shared_ptr and using std::shared_ptr?).After switching to std::shared_ptr I then switched to
std::bind, this time using thestd::placeholders, (thanks richard) the example code now compiles and works correctly.In order to use
std::bindwithboost::asiomake sure thatstd::shared_ptrand thestd::placeholdersare also used.