On Thursday, 4 April 2013 at 07:52:51 UTC, Dicebot wrote:
After some thinking on topic I come to conclusion that rvalue refs _should_ be "scope ref" and stuff like "ref int f(@temp ref int x) { return x; }" is invalid. I can see no valid use case for such an error-prone case.

Perhaps they should, but at least I will give the use case I was thinking of.

If you've got a large struct, you don't want to pass it by value. Say you've got two functions which process and return a Large, and they accept rvalue refs. It might not be too much to ask that a Large always be an lvalue, but let's say you want to pass it directly by value for some reason.

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")));

The use case would allow this to work. And with the kind of error checking suggested in DIP25, this kind of construction would not actually be error prone. 'lar' would be understood as locally derived and could not escape the function it was defined in.

But to speak to your point, this kind of single expression chaining of ref functions might be so rare that there's no great reason to allow it in tandem with rvalues.

Reply via email to