// ----------------- struct Foo { int x; alias this = x; } class Bar { Foo[] data; this() { data.length = 10; } Foo opIndex(uint i) { return data[i]; } void opIndexUnary(string op)(uint i) if (op == "++") { data[i]++; } void opIndexUnaryRight(string op)(uint i) if (op == "++") { data[i]++; } } void main() { auto barfoo = new Bar; ++barfoo[3]; assert(barfoo.data[3] == 1); barfoo[3]++; assert(barfoo.data[3] == 2); } // ----------------- Do you think this code should produce some compilation errors? Bye, bearophile
A small quiz (it's a reprise of an older discussion). This code
compiles with no errors, but do you see anything wrong here?
- A opIndexUnary quiz bearophile
- Re: A opIndexUnary quiz Era Scarecrow
- Re: A opIndexUnary quiz monarch_dodra
- Re: A opIndexUnary quiz bearophile
- Re: A opIndexUnary quiz Dmitry Olshansky
- Re: A opIndexUnary quiz Ali Çehreli
- Re: A opIndexUnary quiz Peter Summerland
- Re: A opIndexUnary quiz monarch_dodra
- Re: A opIndexUnary quiz Peter Summerland
- Re: A opIndexUnary quiz monarch_dodra
- Re: A opIndexUnary quiz Era Scarecrow