'Auto can only be used for template function arguments' what?
Jonathan M Davis
jmdavisProg at gmx.com
Wed Jun 27 10:16:43 PDT 2012
On Wednesday, June 27, 2012 18:13:24 Artur Skawina wrote:
> On 06/27/12 18:04, Artur Skawina wrote:
> > On 06/27/12 17:38, Jonathan M Davis wrote:
> >> On Wednesday, June 27, 2012 13:33:10 Timon Gehr wrote:
> >> saying that it's being passed by value except that you'd like the
> >> compiler to avoid the copy if it can, I don't see why it's restrictive
> >> at all to make>
> > That's not what auto-ref does. We already had this discussion. auto-ref
> > lets
> To clarify - /avoiding a copy/ is not the only, or even the main, use of
> this feature. Copy avoidance mostly matters for structs, and these cases
> should eventually be handled in a better way - but even when that will be
> done, auto-ref will still remain useful.
The _entire_ reason that auto ref on parameters was introduced in the first
place was to have something comparable to C++'s const& which took both
lvalues and rvalues efficiently without having to care which it was. That is the
purpose of the feature. That's it. It may be that you've found other uses for
it, but that's why it exists. The fact that it's implemented the way it is
with templates is entirely an artifact of Walter having misunderstand what
Andrei intended (which was for auto ref to somehow take both lvalues and
rvalues with a single function definition while avoiding copying the lvalues).
So, you may have an argument for why auto ref shouldn't be change, but if so,
you're arguing for something that auto ref was never intended for.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list