opIndexUnary post in-/decrement how to ?
Tejas
notrealemail at gmail.com
Wed Jul 14 15:52:06 UTC 2021
On Wednesday, 14 July 2021 at 15:23:05 UTC, vit wrote:
> 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];
> }
>
>
> ```
I tried changing ```s[0]++``` to ``` s[0] += 1```
the same lvalue problem arose :(
```
Error: `s.opIndex(0)` is not an lvalue and cannot be modified
```
More information about the Digitalmars-d-learn
mailing list