structs are now lvalues - what is with "auto ref"?

Jonathan M Davis jmdavisProg at
Mon Dec 24 09:57:25 PST 2012

On Monday, December 24, 2012 12:37:54 Andrei Alexandrescu wrote:
> An important smoking gun is C++'s min(), which is allows writing unsafe
> code without casts.
> const int& haveANiceDay = min(4, 5);

But what does that have to do with const& for function parameters? I can agree 
that it's bad for local variables like that, but such references aren't legal 
in D anyway - const or not. const& on function paramters merely avoids a copy, 
and as long as you don't take the reference of that parameter (which you can't 
do in D) and then assign it to something or return it, it can't survive past 
the point that it leaves scope.

I get the impression that your complaints about rvalue references stem from 
issues with them that have nothing to do with function parameters, and it's 
the function parameters that everyone cares about.

That being said, I don't think that having const ref take rvalues is a good 
solution for D given how strict its const is - rather I think that we should 
figure out how to make auto ref work for non-templated functions - but I fail 
to see how making const ref accept rvalues would really cause any problems.

- Jonathan M Davis

More information about the Digitalmars-d-learn mailing list