Call site 'ref'

Timon Gehr timon.gehr at gmx.ch
Sun Jan 15 16:29:18 PST 2012


On 01/16/2012 01:30 AM, Peter Alexander wrote:
> On 15/01/12 11:56 PM, Jonathan M Davis wrote:
>> 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
>
> In C++, struct literals are rvalues. C++ just has a special rule that
> const references can bind to rvalues (but non-const references cannot),
> and another special rule that when a const reference binds to a
> temporary it extends the life of the temporary.
>

In C++, a struct literal can be on the lhs of an expression (because of 
the implicit copy assignment operator) but you cannot take it's address 
unless you pass it by const& ;D

> The benefit in C++ is so that you can write one function that takes a
> const reference and it works with rvalues as well as lvalues. Taking by
> value would be too expensive a lot of the time.

In D there is no such thing as a C++ const reference, therefore I think 
it is reasonable that struct literals are lvalues.


More information about the Digitalmars-d mailing list