From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-05-07 09:54:14
Dill, John wrote:
> "Douglas Gregor" <gregod_at_[hidden]> wrote in message
>> Ideally, bind(f, _1, _2, _3)(x, y, z) would be exactly equivalent to
>> f(x, y, z). The current bind() implementation gives us nearly this
>> equivalence because it passes by reference, except that we get a
>> failure at compile time if one tries to pass a literal. Going to
>> passing by value would take us further from that ideal equivalence.
> I see your point. But, what if instead of argument_traits being pass
> by value, it by default passes by T const&? What could be done is to
> have the bind_t arguments be passed by const reference, and then use
> reference_wrapper to do type-selection to pass by reference. It
> still supports literals, and passes by T const& when it can, but
> everything that is passed by reference must have a ref( object ).
Technically, bind supports character literals since they are lvalues. It is
the rvalues that it has a problem with.
Your suggestion is not feasible because in general you do not have control
over the call site. As an example, consider std::for_each; it obviously
doesn't wrap the argument with ref().
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk