
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