Boost logo

Proto :

Subject: Re: [proto] Holding children by copy or reference
From: Yanchenko, Maxim (Maxim.Yanchenko_at_[hidden])
Date: 2013-10-01 22:12:54


Hi Mathias,
 
> The scenario is
>
> terminal a, b, c, r;
>
> auto tmp = a*b*c;
> r = tmp + tmp;
>
> Assuming everything is held by reference, when used in r, tmp will
> refer to a dangling reference (the a*b node).

This is asking for trouble I think.
What about using something like boost::phoenix::let, to explicitly say we have a common subexpression?
Like
r = let( tmp = a*b*c )[ tmp + tmp ];

BTW, I remember there was a discussion about "explicit auto" - was there any movement in that direction?
It could give some protection here...

Thanks,
Maxim


Proto list run by eric at boostpro.com