[asio] boost::asio::placeholders::error vs _1

What is the rationale for boost::asio::placeholders::error and boost::asio::placeholders::bytes_transfered? acceptor_ptr->async_accept ( *socket_ptr , boost::bind( &handle_accept , acceptor_ptr , socket_ptr , boost::asio::placeholders::error ) ); I find this a foreign and confusing usage a boost::bind. Granted I jumped over the Tutorial explicitly introducing these, instead starting with the Tutorial DayTime.3 that addressed my interests. I see the familiar boost::bind, with the lack of _1, _2, so I'm thinking bind is generating a function of type void ()(). ... but handle_accept is expecting a boost::asio::error&??? Thanks, Jeff

Hi Jeff, --- Jeff Flinn <TriumphSprint2000@hotmail.com> wrote:
What is the rationale for boost::asio::placeholders::error and boost::asio::placeholders::bytes_transfered?
The named placeholders date from when some of the callback handlers had arguments like "last_bytes_transferred" as well as "total_bytes_transferred". Even though I wrote the functions, I would forget the order of these parameters.
I find this a foreign and confusing usage a boost::bind. Granted I jumped over the Tutorial explicitly introducing these, instead starting with the Tutorial DayTime.3 that addressed my interests. I see the familiar boost::bind, with the lack of _1, _2, so I'm thinking bind is generating a function of type void ()(). ... but handle_accept is expecting a boost::asio::error&???
That's why it's in a namespace called "placeholders" :) You don't have to use the named placeholders if you don't want to, but I find them a convenient aid in remembering and documenting which arguments I'm expecting to go where. Cheers, Chris

Christopher Kohlhoff wrote:
Hi Jeff,
--- Jeff Flinn <TriumphSprint2000@hotmail.com> wrote:
What is the rationale for boost::asio::placeholders::error and boost::asio::placeholders::bytes_transfered?
The named placeholders date from when some of the callback handlers had arguments like "last_bytes_transferred" as well as "total_bytes_transferred". Even though I wrote the functions, I would forget the order of these parameters.
I find this a foreign and confusing usage a boost::bind. Granted I jumped over the Tutorial explicitly introducing these, instead starting with the Tutorial DayTime.3 that addressed my interests. I see the familiar boost::bind, with the lack of _1, _2, so I'm thinking bind is generating a function of type void ()(). ... but handle_accept is expecting a boost::asio::error&???
That's why it's in a namespace called "placeholders" :) You don't have to use the named placeholders if you don't want to, but I find them a convenient aid in remembering and documenting which arguments I'm expecting to go where.
Yes, I see that all now. For me personally seeing the '_n' in a boost bind call is automatic now in recognizing the resultant function's expected args. We don't use leading/trailing underscores in names by convention, so they really standout. Thanks, Jeff
participants (2)
-
Christopher Kohlhoff
-
Jeff Flinn