|
Boost Users : |
Subject: Re: [Boost-users] [Proto] Storing an Expression Template as a Data Member
From: Eric Niebler (eric_at_[hidden])
Date: 2011-01-09 21:02:08
On 1/9/2011 5:56 PM, Hossein Haeri wrote:
> Hi Eric,
>
>>> Right. Either way, how should I deal with copy
>> construction? Is the deeply copied thing automatic for copy
>> construction? Or, should I make another deep copy each
>> time?
>>
>> A Proto expression that has been passed through proto::deep_copy owns
>> all its sub-objects. The default copy constructor should just do the
>> right thing.
>
> So, do I understand it correctly that there won't be any double-deletion in the following code:
>
> auto ex1 = lit(1) + 3;
Don't EVER do this. It will leave dangling references to intermediate
nodes for all the same reasons that I've given before. If you want to
store an expression in a variable, you MUST pass it through deep_copy.
Do this:
auto ex1 = proto::deep_copy( lit(1) + 3 );
> {
> auto ex2 = ex1;
> }
>
> ex2 will copy everything in ex1, right? (OK, except for function references.)
Right.
-- Eric Niebler BoostPro Computing http://www.boostpro.com
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net