Question about auto ref

Steven Schveighoffer schveiguy at yahoo.com
Fri Mar 15 09:07:09 PDT 2013


On Fri, 15 Mar 2013 11:54:27 -0400, Namespace <rswhite4 at googlemail.com>  
wrote:

> In this thread:
> http://forum.dlang.org/thread/mailman.2989.1356370854.5162.digitalmars-d@puremagic.com
> Jonathan suggested that auto ref could work for non-template functions  
> like this:
> All parameters are declared as ref. For possible rvalues, ​​that are  
> passed to this function, temporary variables are created.
> Furthermore, Andrei said  
> (http://forum.dlang.org/thread/mailman.2989.1356370854.5162.digitalmars-d@puremagic.com?page=2#post-kbcc62:24192v:242:40digitalmars.com)  
> that this would work and would be very easy to implement.
> As it is never happened and was not even suggested in other discussions  
> anymore, there must be a reason why this is a bad idea.
> Can anyone tell me why? Is it because ref is unsafe at this time? Or  
> because 'auto ref' would work then different for non-template and  
> template functions?

2 Simple reasons:  auto means "infer type", so using auto ref is confusing  
the meaning of auto.  For instance, auto ref could actually be valid as a  
return type (the auto is superfluous, but a valid storage class); Second,  
auto ref as currently implemented is useful, and using auto ref for its  
original intended meaning would nix that possibility.

Note, the concept itself is sound, it's just the keyword choice that is  
bad/confusing.

-Steve


More information about the Digitalmars-d-learn mailing list