That's cute, but it really feels like a hack.
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!).

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).


On 8 November 2012 20:28, Dmitry Olshansky <dmitry.olsh@gmail.com> wrote:
11/7/2012 3:54 AM, Manu пишет:

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.
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.


What's wrong with going this route:

void blah(auto ref X stuff){
...lots of code...
}

is magically expanded to:

void blah(ref X stuff){
...that code..
}

and

void blah(X stuff){
        .blah(stuff); //now here stuff is L-value so use the ref version
}

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.

Given that temporaries are moved anyway the speed should be fine and there is as much bloat as you'd do by hand.

Also hopefully inliner can be counted on to do its thing in this simple case.



--
Dmitry Olshansky