So, while I was studying the apropriate template constraints for
my shiny new iota implementation, I found out this funny thing:
import std.stdio;
class Test{
int x = 41;
Test opOpAssign(string op)(int rhs) if (op == "+") {
x += rhs;
return this;
}
}
void main() {
Test t1 = new Test;
//class Test has no opUnary defined, so the following
//gets automagically converted into (t1) += (1)
++t1;
writeln(t1.x); //prints 42, correct!
}
This actually comes really handy, but I couldn't find it into the
language documentation on dlang.org, so it surprised me.
Did I miss it in the language specification? Should we add it
somewhere to the docs?
Anyone with some spare time care to explain briefly what was the
rationale behind this?