Structs, Speed and refs.

Jakob Bornecrantz wallbraker at gmail.com
Tue Oct 23 02:44:05 PDT 2012


Hey everybody!

A bit of background; I'm porting some code over from D1 to D2 and 
I ran into a bit of a problem. I have a bunch of code that looks 
something like this:

class Bar : Other {
   override void func(ref LargeStruct st) {}
}

Bar bar;
LargeStruct foo, too;
bar.func(foo - too);

This compiles just fine in D1 but no longer in D2. Because the 
temp created by "foo - too" is not a lvalue apparently. I don't 
want to remove the "ref" storage type because i still want it to 
be fast. And I rather have neater looking code vs:

LargeStruct foo, too, temp;
temp = foo - too;
bar.func(temp);

One solution is to turn "in" structs into pass by reference, eg 
const ref, but not require lvalue semantics at the call site?

Cheers, Jakob.


More information about the Digitalmars-d mailing list