|
Boost : |
From: Jaakko (jajarvi_at_[hidden])
Date: 2004-04-15 21:39:21
On Apr 15, 2004, at 3:21 PM, Dill, John wrote:
>> Hello John,
>>
>> There's a big technical reason:
>>
>> If bind would have reference semantics, you could not do this:
>>
>> bind(f, 1, _1)
>>
>> Bind would have to take its arguments as
>>
>> template <class F, class A, class B, ...>
>> bind( F, A&, B&, ...)
>>
>> 1 is a non-const rvalue, which cannot be bound to non-const reference.
>
> I think I almost got it now, but I'm still a little confused about
> bind_template.hpp where the list template parameters are A1&, A2&,
> A3&, ...
>
> list1 for example stores a template parameter A1 as "A1 a1;". So this
> ends up not actually being a reference to a normal type T, but to the
> value<T> wrapper class? If not, what type is actually A1& in the
> listN declarations in bind_template.hpp?
>
In bind_template.hpp you are looking at the parameter passing
conventions for the arguments to
a function object that bind has created. Those are passed by reference.
They are temporarily stored into the listN structures, or references to
those arguments are,
in
bind(f, _1, a)(b)
bind(f, _1, a) creates a function object which stores a copy of a,
which defines a unary
function call operator that takes its argument, b in this case, by
reference.
So e.g. list1 is always instantiated with a reference type, and thus it
also stores the arguments
as references.
Hope this helps,
Jaakko
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk