Time to remove ugly auto ref ?

Temtaime via Digitalmars-d digitalmars-d at puremagic.com
Fri Jun 19 05:06:42 PDT 2015


Hi all !
It's too ugly that we cannot write simply « ref in » on functions 
argument.
Many of functions expects a const argument and don't want to know 
is it a temp object or not.

In C++ we can write

struct Number {
Number operator+(const Number &num);
...
};

And then use it as « auto c = a + Number(123);

But in D we cannot. Why ? Because ref doesn't accept temp objects.
We need to use auto ref. OK, but auto ref cannot be used on 
non-templated function.
We need even more make that function templated. It leads to a 
code bloat.

I don't see a reason why « auto ref » even exists.
I think we need to accept temp objects on functions arguments 
marked « const ref » : no auto required and functions is not a 
template.
That change will not break any exiting code : it only allows a 
const ref to accept a temporal object.
In future we can simple deprecate « auto ref » so users will 
adjust their code.


More information about the Digitalmars-d mailing list