ref lost to opDispatch

bearophile bearophileHUGS at lycos.com
Sat Jul 27 08:45:56 PDT 2013


Carl Sturtivant:

> When dispatched through a general argument tuple, ref is lost 
> and the dispatched code therefore does not have the desired 
> side effect. Is there anything I can do about this?

Is this enough?


struct Foo {
     void opDispatch(string f, Args...)(ref Args args) {
         mixin(f ~ "(args);");
     }
}

void bar(ref int y) {
     y--;
}

void main() {
     int x = 100;
     Foo().bar(x);
     assert(x == 99);
     bar(x);
     assert(x == 98);
}


Bye,
bearophile


More information about the Digitalmars-d-learn mailing list