Boost logo

Boost :

Subject: Re: [boost] [Phoenix-3] Is Actor assignable?
From: Joel de Guzman (joel_at_[hidden])
Date: 2011-01-22 17:45:08


On 1/22/2011 10:13 PM, Thomas Heller wrote:
> Joel de Guzman wrote:
>
>> On 1/22/2011 9:02 PM, Joel de Guzman wrote:
>>> On 1/22/2011 8:17 PM, Thomas Heller wrote:
>>>> Joel de Guzman wrote:
>>>>
>>>>> On 1/21/2011 8:39 PM, Michel MORIN wrote:
>>>>>> I have another question about Phoenix 3.
>>>>>> Is the copy assignment of Actors no-op, or does it really copy the
>>>>>> contents?
>>>>>>
>>>>>> Actor a;
>>>>>> Actor b = ...;
>>>>>> a = b; // no-op?
>>>>>
>>>>> It should copy the contents. Thomas?
>>>>
>>>> Not really. It needs to create the assign actor (that means the
>>>> expression template representing the assignment operation.
>>>> It is neither a no-op nor is the assignment "executed". Remember the
>>>> stuff about phoenix being lazy ;)?
>>>
>>> No! That's not the case here. There *is* still the immediate assignment
>>> operator being called when two actors are of the same type (e.g.
>>> when lhs and rhs are phoenix values). In these cases, a *is*
>>> assigned to *b*. Thus, for values, the contents are copied.
>>> Ditto for copy construction of course.
>>
>> Oops, I meant b is assigned to a of course :-P
>
> Seems like i don't stand a chance. I was trying to find a use case where you
> might want the lazy version of the assignment ... couldn't find one.
> Added the operator=(actor const&) to phoenix 3.
>
> Thanks for the hint.

BTW, don't forget to add the non-const overload as well. Proto is pretty
finicky about this:

   operator=(actor& rhs)

I know.. I've been there (with Spirit rules). If you don't do that, and
your rhs is non-const, you'll get a lazy treatment! LOL :P

Regards,

-- 
Joel de Guzman
http://www.boostpro.com
http://boost-spirit.com

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