Boost logo

Proto :

Subject: Re: [proto] Holding children by copy or reference
From: Eric Niebler (eric_at_[hidden])
Date: 2013-09-30 14:19:34


On 9/30/2013 11:08 AM, Mathias Gaunard wrote:
> On 30/09/13 08:01, Eric Niebler wrote:
>
>>> Therefore, to avoid performance issues, I'm considering moving to always
>>> using references (with the default domain behaviour), and relying on
>>> BOOST_FORCEINLINE to make it work as expected.
>>
>> Why is FORCEINLINE needed?
>
> 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).
>
> If everything is inlined, the problem may be avoided because it doesn't
> require things to be present on the stack.

Yikes! You don't need me to tell you that's UB, and you really shouldn't
encourage people to do that.

You can independently control how intermediate nodes are captured, as
opposed to how terminals are captured. In this case, you want a,b,c held
by reference, and the temporary "a*b" to be held by value. Have you
tried this, and still found it to be slow?

-- 
Eric Niebler
BoostPro Computing
http://www.boostpro.com

Proto list run by eric at boostpro.com