Boost logo

Boost :

Subject: Re: [boost] phoenix::bind
From: Eric Niebler (eric_at_[hidden])
Date: 2008-09-30 01:32:10


Joel de Guzman wrote:
> Steven Watanabe wrote:
>> AMDG
>>
>> Eric Niebler wrote:
>>>> The other thorny issue is that lambda expressions aren't Assignable,
>>>> because their operator= creates a new lambda exression instead. This
>>>> might well be unfixable.
>>>
>>> We could make lambdas Assignable by defining the ordinary assignment
>>> operator when the rhs has the same type as the lhs. That would rule
>>> out strange lambdas like "_1 = _1" , but I don't see that as a huge
>>> loss.
>>
>> what about a nullary lambda:
>>
>> vector<int> v1, v2;
>>
>> (ref(v1) = ref(v2))();
>
> Yikes! Yeah :(

It actually doesn't have to be a problem. Imagine:

template<class T>
struct actor
{
     // non-const, does assignment
     actor &
     operator=(actor const &); // non-const assignment

     // const, builds an expression template
     actor</implementation-defined/> const
     operator=(actor const &) const;
};

And then all the operators that build lambda expressions (e.g.
phoenix::ref) return const rvalues. So an expression like:

   (ref(v1) = ref(v2))()

would build an expression template, without having to sacrifice
Assignability.

-- 
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