structs are now lvalues - what is with "auto ref"?
Jonathan M Davis
jmdavisProg at gmx.com
Mon Dec 24 10:20:06 PST 2012
On Monday, December 24, 2012 22:11:58 Dmitry Olshansky wrote:
> 12/24/2012 9:57 PM, Jonathan M Davis пишет:
> > 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?
>
> It relates directly as one may then pass the result of min to fun(const
> ref T);
But the temporary has to be kept in existence for the duration of the
statement, so I don't see how that's a problem. The temporary will last as
long as the function call does. Worst case, the function returns a const ref
to its parameter, but either that ref is used as part of the same statement,
and so the temporary continues to exist and there are no problems, or it's
copied when it's assigned to a variable, and there are no problems. It's the
fact that you can have a const& local variable that breaks things, and D
doesn't allow that.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list