On 29/03/2017 03:28, Christopher Pisz via Boost-users wrote:
If I followed what you wrote in your post correctly, I would end up with:
void start_accept() { tcp_connection::pointer new_connection = tcp_connection::create(acceptor_.get_io_service());
//auto callback = std::bind(&tcp_server::handle_accept, this, new_connection, std::placeholders::_1); const std::function
callback = std::bind(&tcp_server::handle_accept, this, new_connection, std::placeholders::_1); acceptor_.async_accept(new_connection->socket(), std::bind(callback, this, boost::asio::placeholders::error)); }
Which does not compile. I don't know why I'd bind something that is already bound or what this would mean in the context of the second bind.
All that bind does is to return a functor that has fewer parameters than
another functor, by "binding" some specific values to some parameters
while letting others pass through from the caller. You can bind as many
times as you like (although there's a slight performance hit due to the
indirection).
(Though in this context there's no point in doing two binds -- it's
always possible to write that as a single bind, or as a lambda. You'd
only bind multiple times if it needed to happen in different contexts.)
Now, have a look at the code you wrote:
const std::function