ref lost to opDispatch

Artur Skawina art.08.09 at gmail.com
Sat Jul 27 08:53:38 PDT 2013


On 07/27/13 17:09, Carl Sturtivant wrote:
> 
> I ran into the following behavior.
> 
> ==============================================
> void main() {
>     int x = 100;
> 
>     B().modify( x, 99);
>     writeln( x); //still 100
> 
>     modify( x, 99);
>     writeln( x); //now is 99
> }
> 
> void modify( ref int x, int y) { x = y; }
> 
> struct B {
>     void opDispatch(string f, Args...)( Args args) {
>         mixin( f~"(args);");
>     }
> }
> ==============================================
> 
> 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?

   void opDispatch(string f, Args...)(auto ref Args args)

artur


More information about the Digitalmars-d-learn mailing list