Question about auto ref

Jonathan M Davis jmdavisProg at gmx.com
Mon Mar 25 15:59:45 PDT 2013


On Monday, March 25, 2013 23:35:06 Namespace wrote:
> > Because the number of instantiations of the template could grow
> > exponentially
> > as the number of auto ref parameters grows. Being able to use
> > the trick with
> > the temporary with templated functions could really help reduce
> > template bloat
> > when the current meaning of auto ref is not necessary, but that
> > means coming
> > up with a new attribute rather than reusing auto ref with
> > non-templated
> > functions.
> 
> I use the "trick" with the temporary. But why introduce rather a
> new attribute?
> I thought the real reason why auto ref was first introduced was
> to solve the rvalue ref problem. Now we could do it. So what's
> wrong with auto ref for non-
> template functions?
> I'm afraid that the introducing of a new attribute means to spend
> a lot of time. Is that really needed? :/ Or am I wrong?

The problem is that we need the temporary trick with templated functions as 
well as non-templated functions. auto ref on templated functions as it stands 
is great for creating parameters that retaining all of the attributes on a 
type - including refness - but it causes template bloat, which in the case 
that auto ref was originally intended to solve is completely unnecessary. The 
temporary trick will work just fine for that, but you can't use auto ref for 
that on templated functions, because we'd lose out on what it currently does, 
which is needed for forwarding arguments (much as it was accidental that we 
got that ability). So, in order to have the temporary trick with templated 
functions, we need a new attribute. That being the caes, there's no point in 
implementing auto ref for non-templated functions, as they should just use the 
same attribute as would be used with template functions.

> I haven't heard of it.
> Would be very nice if you could do it and post the link. :)

I can try, but the search of my e-mail client sucks, so it's always a pain for 
me to find anything in old posts.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list