c++ - Should std::bind be compatible with boost::asio? -



c++ - Should std::bind be compatible with boost::asio? -

i trying adapt 1 of boost::asio examples utilize c++11 / tr1 libraries possible. original code looks 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 replace boost::bind std::bind 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 big error message, ends with:

/usr/include/c++/4.4/tr1_impl/functional:1137: error: return-statement value, in function returning 'void'

i using gcc version 4.4 boost version 1.47

i expected boost::bind , std::bind interchangeable.

i have solution

the problem when first tried switch std::bind , std::shared_ptr still using boost::asio::placeholders std::bind, resulted in big amount of template compiler errors, tried switch piecemeal.

i first tried switching boost::shared_ptr std::shared_ptr, failed because boost::bind not work std::shared_ptr out specialisation of template get_pointer<typename t> std::shared_ptr (see: how resolve conflict between boost::shared_ptr , using std::shared_ptr?).

after switching std::shared_ptr switched std::bind, time using std::placeholders, (thanks richard) illustration code compiles , works correctly.

in order utilize std::bind boost::asio create sure std::shared_ptr , std::placeholders used.

c++ boost c++11 boost-asio

Comments

Popular posts from this blog

delphi - blogger via idHTTP : error 400 bad request -

c++ - cuda, pycuda -- how to write complex numbers -- errors:class "cuComplex" has no member "i" -

How do I check if an insert was successful with MySQLdb in Python? -