That's cute, but it really feels like a hack.<div>All of a sudden the debugger doesn't work properly anymore, you need to step-in twice to enter the function, and it's particularly inefficient in debug builds (a point of great concern for my industry!).</div>
<div><br></div><div>Please just with the compiler creating a temporary in the caller space. Restrict is to const ref, or better, in ref (scope seems particularly important here).</div><div class="gmail_extra"><br><br><div class="gmail_quote">
On 8 November 2012 20:28, Dmitry Olshansky <span dir="ltr"><<a href="mailto:dmitry.olsh@gmail.com" target="_blank">dmitry.olsh@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
11/7/2012 3:54 AM, Manu пишет:<div class="im"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
If the compiler started generating 2 copies of all my ref functions, I'd<br>
be rather unimpressed... bloat is already a problem in D. Perhaps this<br>
may be a handy feature, but I wouldn't call this a 'solution' to this issue.<br>
Also, what if the function is external (likely)... auto ref can't work<br>
if the function is external, an implicit temporary is required in that case.<br>
<br>
</blockquote>
<br></div>
What's wrong with going this route:<br>
<br>
void blah(auto ref X stuff){<br>
...lots of code...<br>
}<br>
<br>
is magically expanded to:<br>
<br>
void blah(ref X stuff){<br>
...that code..<br>
}<br>
<br>
and<br>
<br>
void blah(X stuff){<br>
        .blah(stuff); //now here stuff is L-value so use the ref version<br>
}<br>
<br>
Yeah, it looks _almost_ like a template now. But unlike with a template we can assume it's 2 overloads _always_. External  fucntion issue is then solved by treating it as exactly these 2 overloads (one trampoline, one real). Basically it becomes one-line declaration of 2 functions.<br>

<br>
Given that temporaries are moved anyway the speed should be fine and there is as much bloat as you'd do by hand.<br>
<br>
Also hopefully inliner can be counted on to do its thing in this simple case.<span class="HOEnZb"><font color="#888888"><br>
<br>
<br>
<br>
-- <br>
Dmitry Olshansky<br>
</font></span></blockquote></div><br></div>