Boost logo

Boost Users :

Subject: Re: [Boost-users] boost::asio buffer questions, and boost::bind question
From: Lars Viklund (zao_at_[hidden])
Date: 2012-09-07 02:15:59


On Thu, Sep 06, 2012 at 09:17:38PM -0600, Littlefield, Tyler wrote:
> Finally, my boost::bind question.
> I was curious how that worked out. When I use _1, _2 as placeholders,
> does the templating get substituted in somehow? Does it somehow
> construct an object that just has a () operator to take arguments? Also,
> if I wanted to write something to let me pull in the errors like
> placeholders, how do placeholders work/get translated out?

It indeed constructs a object of a secret callable class which stores
all the concrete arguments by value inside.

When invoked through operator (), the arguments, they're mapped to any
corresponding placeheld slots in the original function and the stored
values are passed as the parameter they're glued to.

As for Asio's named placeholders "error" and "bytes_transferred",
they're just aliases for Bind's _1 and _2. They just exist to make the
bind site a bit more legible if you happen to use a callable-maker that
can leverage Bind-style placeholders.

In the end, Asio doesn't care if you use Boost.Bind, Boost.Phoenix,
std::bind, Boost::Lambda, MakeAwesomeFastDelegate or some arbitrary
other callable, as long as the callable satisfies the requirements put
forth by ReadHandler [1], WriteHandler, etc. w.r.t. the argument types and
amounts.

[1] http://www.boost.org/doc/libs/1_51_0/doc/html/boost_asio/reference/ReadHandler.html

-- 
Lars Viklund | zao_at_[hidden]

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net