On 02/08/2015 01:05 PM, Robin wrote:

the postfix inc and decrement expressions are
inherited from BinExpr (binary expression) which define their second
expression to be an integer expression with a value of 1.

Post-increment cannot be overloaded in D. It is always implemented in terms of pre-increment (or +=):

  http://dlang.org/operatoroverloading.html

Although I can't find it on the spec, I think it used to be spelled out that pre-increment (and post-increment) could be the equivalent of "+= 1". I am pretty sure about that because my notes say so! :p (because I based everything on what I knew to be correct at the time).

  http://ddili.org/ders/d.en/operator_overloading.html

Quoting myself:

"if an opBinary overload supports the duration += 1 usage, then opUnary need not be overloaded for ++duration and duration++. Instead, the compiler uses the duration += 1 expression behind the scenes. Similarly, the duration -= 1 overload covers the uses of --duration and duration-- as well."

Perhaps that's why the compiler uses a binary operator for post-increment.

Ali

Reply via email to