In this example : https://www.boost.org/doc/libs/1_83_0/doc/html/boost_asio/tutorial/tutdaytime3.html#boost_asio.tutorial.tutdaytime3.removing_unused_handler_parameters

It is written :

You may have noticed that the error, and bytes_transferred parameters are not used in the body of the handle_write() function. If parameters are not needed, it is possible to remove them from the function

However, it seems like everywhere else ( https://www.boost.org/doc/libs/1_80_0/doc/html/boost_asio/reference/async_write.html https://live.boost.org/doc/libs/1_83_0/doc/html/boost_asio/reference/WriteHandler.html ), the documentation says that the function-like should match the signature.

I tried with an empty lambda, and indeed, it complains about the signature. Is it boost::bind that allows async_write to call it discarding the argument ?

Where is it documented in the official boost documentation ?

1

There are 1 best solutions below

0
On

As supposed in the question it's boost::bind that allows it.

Is using boost::bind to pass more arguments than expected safe?

The result of boost::bind can be sefely called with more arguments :

Note that, in the last example, the function object produced by bind(g, _1, _1, _1) does not contain references to any arguments beyond the first, but it can still be used with more than one argument. Any extra arguments are silently ignored, just like the first and the second argument are ignored in the third example.

https://www.boost.org/doc/libs/1_83_0/libs/bind/doc/html/bind.html#bind.purpose.using_bind_with_functions_and_fu

Since a bound function with boost::bind can be called with extra argument, the compiler does not complain.