auto ref and non-templated functions

Jonathan M Davis jmdavisProg at gmx.com
Tue Dec 25 02:36:03 PST 2012


On Tuesday, December 25, 2012 11:14:40 Namespace wrote:
> > What does this generate?
> > 
> > auto foo(auto ref S a, auto ref S b, auto ref S c, auto ref S
> > d) { ... }
> > 
> > 16 different functions, one for each combination? Sounds like a
> > bad idea.
> 
> In my opinion, this should produce only two functions:
> #1: auto foo(ref S a, ref S b, ref S c, ref S d) { ... }
> #2: auto foo(S a, S b, S c, S d) { ... }

So, you'd take the performance hit of copying all of your function arguments 
simply because one of them was an rvalue?

No. I think that Peter's point shows exactly why this is a bad idea.

However, creating only one version of the function which takes all refs and 
specifcally creating variables underneath the hood for any rvalues so that 
they can be passed to the function still seems like it could work.

- Jonathan M Davis


More information about the Digitalmars-d mailing list