Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-02-19 08:26:12


Brian McNamara wrote:
> On Wed, Feb 18, 2004 at 05:04:11PM -0300, Fernando Cacciola wrote:
>> Referencial Integrity and Side Effects:
>> =========================
> ...
>> What I'm trying to say is that I don't like the current design were
>> functoids are prescribed to take only reference to const parameters,
>> for a variety of reasons:
> ... [ a number of good arguments, elided ]
>
> A number of people have voiced similar complaints, and I am gradually
> being worn down. I think one of the reasons I resist it is that I don't
> like how boost::lambda has dealt with the issue. Notably, examples
> like
>
> // From 5.3.2 of the lambda docs
> //
>
>
> http://www.boost.org/libs/lambda/doc/ar01s05.html#sect:bind_expressions
> bind(&A::set_j, a, _1)(k); // a.j == 0, as a copy of a is modified
> bind(&A::set_j, _1, 1)(a); // a.j == 1
>
> where reference-versus-copy depends upon the precise "timing" of
> binding a function argument to a value, ...

There is no "precise timing" issue here, the rule is simple. Every argument
passed to bind() is copied, whether it is &A::set_j, a, _1, or 1.

An example that may illustrate your point is

    std::cout << _1

where 'std::cout' is taken by reference, versus

    _1 << 1

where '1' is copied. But std::cout << _1 is just a convenience spelling for
ref(std::cout) << _1, which is reference-consistent. It's too prevalent in
motivating examples to not warrant special treatment. :-)


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk