opIndexUnary post in-/decrement how to ?

vit vit at vit.vit
Wed Jul 14 15:23:05 UTC 2021


On Wednesday, 14 July 2021 at 15:19:03 UTC, vit wrote:


```d
import   std.stdio;

struct abc{
     int[100] a;

     struct Proxy{
         abc* ptr;
     	const int index;

         int opUnary(string op : "++")(){
         	return ++ptr.a[index];     //add missing ++
         }
     }

     Proxy opIndex(int index)return{
         return Proxy(&this, index);
     }
}

void main (){
     abc s;
     s[0]++;
     ++s[0];
}


```


More information about the Digitalmars-d-learn mailing list