Boost logo

Boost :

Subject: Re: [boost] [GSoC][Phoenix3] Regarding mutability of arguments passed to phoenix expressions
From: Eric Niebler (eric_at_[hidden])
Date: 2010-06-11 14:12:15


On 6/11/2010 1:24 PM, Giovanni Piero Deretta wrote:
> On Fri, Jun 11, 2010 at 6:03 PM, Eric Niebler <eric_at_[hidden]> wrote:
>> Well, there's a hitch.
>>
>> ref[ bigobj += _1 ]
>>
>> Users might reasonably expect this to not make a copy of bigobj, and the
>> way to avoid it is not obvious:
>>
>> ref[ ref(bigobj) += _1 ]
>>
>> Clearly the user has already stated their intention to capture bigobj by
>> reference and shouldn't have to say it again.
>>
>> I think default capture modes may be unworkable if we want the default
>> mode to be by-value.
>>
>
> unless you forbid 'naked' lambdas:
>
> int x = 0;
> auto f0 = lambda [ x += _1 ]; // capture x by val
> auto f1 = lambda_r [ x += _1 ]; // capture x by ref
> auto f2 = x += _1 ; // just a proto expression tree, not a lambda
>
> f0(1); //ok
> f2(1); //ok
> f3(1); // no operator()
>
> The lambda syntax becomes more heavy weight, but lambdas do stand up
> more in code. You would have to protect nested lambdas anyway ...

That's true, and I /personally/ wouldn't be opposed to that; I just
don't have a strong preference. This should be Joel's call.

-- 
Eric Niebler
BoostPro Computing
http://www.boostpro.com

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