On Wednesday, 14 July 2021 at 10:07:38 UTC, wjoe wrote:
I'm want to do something like this
```D
part_int_t!(1,2,3) i;
auto x = -i[0];
--i[1]; // 1
i[1]++; // 2
```
I think the operator I need to overload would be opIndexUnary
which I did.
(1) compiles.
(2) doesn't - the compiler complains that i.opIndex isn't an
lvalue and can't be modified.
The language spec says that Post in- and decrement are
rewritten but something's fishy.
What's going on behind the scene and how can I make it work?
Please check the language spec here:
https://dlang.org/spec/operatoroverloading.html#postincrement_postdecrement_operators
You can't directly overload the postincrement operator.
You need to rewrite it like:
``` {auto a = i[1] , ++i[1] , a} //note the , not the ;```
Sorry I can't provide something even more concrete.