Incorporating D

Namespace rswhite4 at googlemail.com
Fri Jan 25 14:27:48 PST 2013


On Friday, 25 January 2013 at 22:22:44 UTC, Szymon wrote:
> So structs in D are always passed by-value? That is 
> unfortunate...
>
> On Friday, 25 January 2013 at 22:20:32 UTC, Namespace wrote:
>> On Friday, 25 January 2013 at 22:16:11 UTC, Szymon wrote:
>>> In C++ rv-refs do not help with structs (PODs). Do you mean D 
>>> has no refs / pointers for struct passing?
>>
>> I meant that we have nothing comparable with const&.
>> const& int C++ accept both, lvalues and rvalues. If it is an 
>> lvalue it is taken by reference and isn't copied.

Not if you pass them as ref.
struct A { }
void foo(ref A a) { }

Now foo takes A's by reference. But _only_ lvalues:
A a;
foo(a);
So this is (currently) not possible:
foo(A());


More information about the Digitalmars-d mailing list