This allows you to bind (or "bind") your own data using the function you want to call the library, without a library that needs to know anything about your data.
Since you are looking at Boost.Asio, look at the tutorial for binding arguments to a handler . They have a function that they want to use as a handler, for which they need pointers to their own data, the timer itself and the counter:
void print(const boost::system::error_code& , boost::asio::deadline_timer* t, int* count) {
The async_wait timer async_wait calls the user-called function when the timer expires; but gives only the first of these arguments. The handler has the form
void handler( const boost::system::error_code& error // Result of operation. );
Thus, we can use bind to convert our function (wanting three arguments) to a unit that wants only one argument, by specifying values โโthat should be passed as the other two:
t.async_wait(boost::bind(print, boost::asio::placeholders::error, &t, &count));
The result of bind is a function object (i.e. an object of type class that overloads the function call operator() , operator() ), which in this case takes one argument. The placeholders::error argument says that the first argument is still the argument of the new function type; the other two arguments are assigned the values &t and &count when calling a new function. Therefore, if we ourselves called it:
auto f = boost::bind(print, boost::asio::placeholders::error, &t, &count) f(some_error);
this will have the same effect as calling the original function with these arguments:
print(some_error, &t, &count);
Now that the timer expires, our function is called with the arguments we provided, without the Asio library, which should know anything about them.