Question about auto ref

Jonathan M Davis jmdavisProg at gmx.com
Tue Mar 26 15:11:42 PDT 2013


On Tuesday, March 26, 2013 22:55:56 Minas Mina wrote:
> Why is "const ref" not a good choice?

I really don't want to get into that again. There have been a number of 
discussions on it in the main newsgroup which you can search for, but Andrei 
considers it to be a major mistake of C++ that const& accepts rvalues, and he 
does not want to repeat that in D. So, just like ref, const ref in D accepts 
only lvalues (they're just const instead of mutable), and that's not going to 
change.

auto ref was introduced specifically to solve the problem of having a function 
take either lvalues or rvalues efficiently, but Walter misunderstood how Andrei 
meant for it to work, and the way Walter implemented it only works with 
templated functions. But we can't change how it works, because it turns out 
that the way it was implemented has other benefits with regards to forwarding 
the types of arguments. We have a good idea of how to implement what auto ref 
should have been. We just need a new attribute for it. It's really not that 
complicated. It just requires a good name.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list