Summary: Restriction on op= can be lifted
           Product: D
           Version: 2.025
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2

The section on opIndex and opIndexAssign states that op=, ++, and -- operators
can't be supported.

However, if we have:

struct S {

 ref <type> opIndex(size_t idx) {...}


then, the following code will do what we expect

S s;
s[i] += 4;

as the += ends up calling opIndex.  At least, this is what dmd 2.026 appears to
do.  If the docs are adjusted accordingly, then that wart is removed.

As a side note, opIndexAssign doesn't appear necessary at all if we do things
this way.  As long as opIndex is declared with ref, it can be used as lvalue
and rvalue.


Reply via email to