<div dir="ltr">On 24 April 2013 11:22, kenji hara <span dir="ltr"><<a href="mailto:k.hara.pg@gmail.com" target="_blank">k.hara.pg@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">Temporaries which created on stack to pass an address to `scope ref` parameter would be destroyed after the "current statement/expression".<div><br></div><div>T rvalue();</div><div><br></div><div>
void foo(scope ref T) { ... }</div>
<div>foo(rvalue()); // here is "current statement/expression"</div><div>// lowered to: { auto __tmp = rvalue(); foo(__tmp); __tmp.~this(); };</div><div><br></div><div>Note that the lifetime of taken rvalue is mostly same as non-ref parameter case.</div>
<div>void bar(T arg) { ... arg.~this(); }</div><div>bar(rvalue());</div><div>// the rvalue argument is moved into the function 'bar', and destroyed inside function.</div></div></blockquote><div><br></div><div style>
The important distinction is that with scope ref, a temps life can be prolonged and cascaded via return values.</div><div style>This is very important behaviour, I couldn't write an efficient&convenient matrix library for instance without this, i would have to choose one or the other.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><span class="HOEnZb"><font color="#888888"><div><br></div><div>Kenji Hara</div></font></span></div>
<div class="HOEnZb"><div class="h5"><div class="gmail_extra">
<br><br><div class="gmail_quote">2013/4/24 Diggory <span dir="ltr"><<a href="mailto:diggsey@googlemail.com" target="_blank">diggsey@googlemail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Wednesday, 24 April 2013 at 00:54:12 UTC, kenji hara wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>
2013/4/24 Manu <<a href="mailto:turkeyman@gmail.com" target="_blank">turkeyman@gmail.com</a>><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
"The r-value being passed is assigned to a stack allocated temporary,<br>
which has a lifetime that is identical to any other local variable, ie, the<br>
lifetime of the function in which it appears."<br>
There, I defined it.<br>
<br>
</blockquote>
<br></div><div>
Good definition. If add more,<br>
"getting address of "scope" parameter would be disallowed, at least in<br>
@safe code, because it would be regarded as the escape of stack allocated<br>
temporary."<br>
<br>
Kenji Hara<br>
</div></blockquote>
<br>
Why does the temporary need to exist any longer than the current statement? (the current lifetime of temporaries are the statement or expression). Surely any longer is just wasting stack space.<br>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div></div>