OpIndex/OpIndexAssign strange order of execution

SrMordred patric.dexheimer at gmail.com
Sun Sep 17 18:52:39 UTC 2017


struct Test{
     @property int value(){
         writeln("property value : ", _value);
         return _value;
     }
     int _value;
     Test opIndex( string index )
     {
         writeln( "opIndex : index : ", index );
         return this;
     }

     Test opIndexAssign(int value, string index )
     {
         writeln( "opIndexAssign : value : ", value, " , index : 
", index );
         this._value = value;
         return this;
     }
}

Test t;
t["a"] = 100;
t["b"]["c"] = t["a"].value;

//OUTPUT:
opIndexAssign : index : a , value : 100
opIndex : index : b
opIndex : index : a
property value : 100
opIndexAssign : index : c , value : 100

//EXPECTED OUTPUT
opIndexAssign : index : a , value : 100
opIndex : index : a
property value : 100
opIndex : index : b
opIndexAssign : index : c , value : 100

Is this right?

I find unexpected this mix of operations on left and right side 
of an equal operator.



More information about the Digitalmars-d-learn mailing list