Hi,

Is there a way to get post increment and pre increment working properly in this scenario?

import std.stdio;

struct A {
    int[] a;
    this(int a) { this.a = [a]; }
    auto opUnary(string op)(){
        return A(mixin(op ~ "this.a[0]"));
    }
}

void main() {
    auto a = A(0);
    int b = 0;
writeln(a++, ":", b++); // 1, 0 <-- wrong post increment result
    writeln(++a, ":", ++b); // 2, 2
}

If I switch the order of the mixin expression (i.e. "this.a[0]" ~ op) then the pre increment does not work.

Any tips?

Cheers
- Ali

Reply via email to