Question about auto ref

Jonathan M Davis jmdavisProg at gmx.com
Mon Mar 25 15:13:56 PDT 2013


On Monday, March 25, 2013 20:43:29 Namespace wrote:
> > Basically, someone needs to implement it and then talk Walter
> > into accepting
> > it. That'll be easier for someone like Kenji, who's already a
> > major
> > contributor, but in theory, anyone can do it. It's just that
> > there's a high
> > risk that the pull request would languish for a while. And it
> > would probably
> > need to be implemented with a name other than auto ref in order
> > to avoid the
> > aforementioned problems, and having to agree on that could
> > cause further
> > delay.
> 
> I am currently working in the required part of the compiler, but
> I need help and other opinions.
> So far I've tried both: an implementation for auto ref and ref
> const.
> 
> -> auto ref:
> auto ref for non-template functions. In this case (as you had
> suggested it once) temporary variables are created for rvalues.
> Thus the behavior of auto ref would be different for template and
> non-template functions. But I do not see how that would be
> problematic.

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.

> -> ref const:
> const ref creates for rvalues a temporary variable that is then
> passed to the function. Advantage: It is like C++. Disadvantage:
> it could break code and you get always a const parameter.

Andrei is flat out against this. I wouldn't expect that te over happen.

> As I said, I've tried both ways before. But I like to hear other
> opinions which of both would be more preferred.
> And I would be glad about any kind of help (looking on my code
> etc.).
> Maybe we could convince Walter and Andrei with a finished
> implementation.
> I hope that no one like to have a new syntax for this kind of
> thing because then we will discuss another year...

We pretty much need a new attribute. IIRC, Kenji had a suggestion for what it 
would be, but I don't remember what it was now. I'd have to go digging through 
the archives to find it.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list