My thoughts & tries with rvalue references

Dicebot m.strashun at gmail.com
Fri Apr 5 00:45:32 PDT 2013


On Friday, 5 April 2013 at 00:12:33 UTC, Zach the Mystic wrote:
> struct Large { ... }
> ref Large process1(@temp ref Large a) { return a; }
> ref Large process2(@temp ref Large a) { return a; }
>
> Large* lar = &process2(process1(Large("Pass"," a ", "Large", 
> "here")));

This is exactly type of code I consider to be bad style and want 
to see banned. Function that gets rvalue ref should never return 
it as it knows nothing about its lifetime. Actually, I can't even 
find scope definition for temporaries in dlang.org, but it is 
hardly a good thing to rely on anyway. Best is to assume that 
when function is gone, so is rvalue temporary.

Your code begs for using plain refs and storing Large in a stack 
variable before calling function chain. May look a bit less 
convenient but much more reliable and understandable.


More information about the Digitalmars-d mailing list