If the compiler started generating 2 copies of all my ref functions, I'd be rather unimpressed... bloat is already a problem in D. Perhaps this may be a handy feature, but I wouldn't call this a 'solution' to this issue.<div>
Also, what if the function is external (likely)... auto ref can't work if the function is external, an implicit temporary is required in that case.</div><div class="gmail_extra"><br><br><div class="gmail_quote">On 7 November 2012 01:37, martin <span dir="ltr"><<a href="mailto:kinke@libero.it" target="_blank">kinke@libero.it</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Tuesday, 6 November 2012 at 22:32:57 UTC, Manu wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
But it only really makes sense in the context of templates...?<br>
Why should something called 'auto ref' provide fabrication of temporaries<br>
for the purpose of passing rvalues to functions that receive ref args?<br>
<br>
How does auto ref (under some different definition/implementation) address<br>
the rvalue problem?<br>
</blockquote>
<br></div>
The thing is that currently there are 2 workarounds. You described the first one - allocating temporaries manually to obtain referenceable lvalues:<div class="im"><br>
<br>
void func(ref in Vector m);<br></div><div class="im">
Vector v1v2PlusSomeStuff = v1*v2 + Vector(10, 20, 30);<br>
func(v1v2PlusSomeStuff);<br>
<br></div>
The other, also painfully annoying workaround is overloading func:<br>
<br>
void func(in ref Vector m);<br>
void func(in Vector m);<div class="im"><br>
func(v1*v2 + Vector(10, 20, 30));<br>
<br></div>
'auto ref' implements the second workaround (via a template) and therefore requires a single, but templated func() implementation:<br>
<br>
void func(T)(in auto ref T m);<br>
<br>
This template, as I understand it, gets expanded to:<br>
<br>
void func(T)(in ref T m); // for lvalues<br>
void func(T)(in T m);     // for rvalues<br>
<br>
So for non-templated functions, I suggest 2 options:<br>
<br>
1) The previously described auto-templates (identical 'auto ref' semantics), where a function with 'auto ref' parameters is treated as implicit template. This may lead to code-bloating (for larger functions) and/or higher performance for rvalue arguments (rvalues passed to value arguments are moved, not copied; we therefore gain nothing by passing a reference, but incur a slight performance hit due to pointer indirection instead of accessing directly the rvalue on the stack). OR<br>

2) Simple under-the-hood temporary lvalue declaration by the compiler (for rvalues passed to 'const ref' parameters) - that would be a handy implementation of the first workaround.<br>
<br>
I hope you get my point. :)<br>
</blockquote></div><br></div>