Beast: Beast and std::bind vs boost::bind

Created on 21 Mar 2019  路  6Comments  路  Source: boostorg/beast

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?

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 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.

All 6 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MarcoRhayden picture MarcoRhayden  路  6Comments

vinniefalco picture vinniefalco  路  4Comments

maddinat0r picture maddinat0r  路  4Comments

clekby picture clekby  路  7Comments

monada99 picture monada99  路  5Comments