'Auto can only be used for template function arguments' what?

Jonathan M Davis jmdavisProg at gmx.com
Tue Jun 26 22:14:52 PDT 2012


On Wednesday, June 27, 2012 07:02:28 Mehrdad wrote:
> On Wednesday, 27 June 2012 at 04:26:08 UTC, Jonathan M Davis
> 
> wrote:
> > And how would that work? auto ref duplicates the function. If
> > you pass it an lvalue, then it generates a ref version.
> 
> Two solutions:
> 
> - Turn 'auto ref' into 'ref', but simply have the compiler
> generate a copy for the caller if he wants to pass by value?

That at least sounds like it would work. Walter may have a reason why it 
doesn't though, since he's the one that said that he didn't think that it was 
possible. Maybe he just didn't think of it, or maybe it causes some other 
problem that I can't think of.

> - Treat it as though it were a templated parameter. Why does it
> make any difference here?

You can't just templatize functions. There are places where templated 
functions _can't_ be used. For instance, templated functions can't be virtual. 
And a templated function _can_ be used, then the programmer can just 
templatize it themselves, avoiding any possible issues caused by functions be 
automatically templatized.

- Jonathan M Davis


More information about the Digitalmars-d mailing list