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

Jonathan M Davis jmdavisProg at gmx.com
Tue Jun 26 21:25:54 PDT 2012


On Wednesday, June 27, 2012 06:03:12 Mehrdad wrote:
> On Wednesday, 27 June 2012 at 03:54:12 UTC, Jonathan M Davis
> 
> wrote:
> > That isn't legal. auto ref can only be used with templated
> > functions.
> > 
> > - Jonathan M Davis
> 
> The trouble is, distinguishing between when it should be illegal
> seems like a blur to me.
> 
> Consider all the cases like:
> 
> - <Regular method>
> - <Mixin method>
> - <Template method>
> - Lambdas (in all forms)
> - Template class, <regular method>
> - Template class, <template method>
> - Regular class, <template method>
> - Regular class, template method, <mixin method>
> - Regular class, regular method, <mixin method>
> - Template class, regular method, <mixin method>
> - <Templates inside mixins>
> - yada yada
> 
> 
> 
> It becomes a *nightmare* to try to get everything right, when
> you're dealing with templates and mixins. And you run into bugs
> like this.
> 
> Why not just allow 'auto ref' for every function type?

And how would that work? auto ref duplicates the function. If you pass it an 
lvalue, then it generates a ref version. If you pass it an rvalue, it 
generates a non-ref version. For it to work with a normal function, you would 
somehow have to make it work with only one version. The original idea was for 
it to work for all functions, but Walter said that it can't be done. So, it 
only works with templated functions.

So, auto ref is pretty much a failure IMHO, since it was supposed to solve the 
problem of a single function being able to take both lvalues and rvalues 
efficiently.

There has been some discussion of making it so that rvalues work with ref in 
order to fix that problem, but that hasn't been sorted out yet, since it has to 
be done in a way that avoids the problems that C++ has allowing const& to take 
lvalues.

- Jonathan M Davis


More information about the Digitalmars-d mailing list