Hi there!
I am quite curious should I use std::bind() or boost::bind() with Boost/Beast code.
Examples from pure Boost currently using boost::bind(). But in some cases (like async_accept() from boost::asio::ip::tcp::acceptor) I can't use boost::bind() on pure boost.
At the same time Beast examples using std::bind().
Is there any considerations/recommendations regarding this matter?
You can use either one, as long as you don't try to mix the placeholders. If you use boost::bind, you have to use boost placeholders. If you use std::bind, you have to use std placeholders.
However, Beast 1.70 introduces a new function bind_front_handler which is more lightweight, and doesn't use placeholders at all, so it is recommended to use that instead of bind. All the examples have been updated.
What about boost::beast::bind_handler:
The passed handler and arguments are forwarded into the returned handler, whose associated allocator and associated executor will will be the same as those of the original handler.
?
bind_handler suffers from the same problem as boost::bind and std::bind. It supports placeholders, and is heavy to compile. I try not to use it anymore, because bind_front_handler is faster and lighter on builds.
Thank you Vinnie!
Especially for insight into bind alternatives.
@vinniefalco How does bind_front_handler compare to a lambda, in terms of being lightweight?
No idea. If I had to guess, I would say the lambda is slightly more lightweight.
Most helpful comment
You can use either one, as long as you don't try to mix the placeholders. If you use
boost::bind, you have to use boost placeholders. If you usestd::bind, you have to use std placeholders.However, Beast 1.70 introduces a new function
bind_front_handlerwhich is more lightweight, and doesn't use placeholders at all, so it is recommended to use that instead of bind. All the examples have been updated.