Call site 'ref'
Jonathan M Davis
jmdavisProg at gmx.com
Sun Jan 15 15:56:32 PST 2012
On Monday, January 16, 2012 00:41:14 Timon Gehr wrote:
> Well, struct literals are lvalues, at least in DMD.
Yeah. I don't understand that. I've argued about it with Walter before.
Apparently they are in C++ as well. I don't understand it. It makes it so that
void func(ref S val)
S bar();
works with
func(S(42));
but not
func(bar());
It seems completely arbitrary to me that it works this way and has IMHO _zero_
benefits. And I know that newbies have run into the problem and been completely
confused by it (e.g. http://stackoverflow.com/questions/6986175/const-ref-and-
rvalue-in-d ). _I_'ve been confused by it. I was stunned to find out that there
was _any_ difference in the language between a struct literal and an identical
struct returned from a function.
It's not as big an issue in C++, because using & is fairly rare in C++ unless
its const, and const & will take temporaries. But in D, it's _definitely_ an
issue IMHO. I really think that struct literals should be considered rvalues.
I do _not_ understand why they aren't or why anyone ever thought that it was a
good idea for them to be lvalues.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list