On Sunday, 24 May 2015 at 15:13:41 UTC, Vladimir Panteleev wrote:
Could you elaborate on what these magic semantics are?
and no easy solution exists for the ++aa[key1][key2] case.
Is this specific to the pre-increment? aa[key1][key2]++ is
generally a useful pattern.
This applies to pre/post increment as well as assignment and
opOpAssign.
When an lvalue is needed the compiler will call a special runtime
function GetX to obtain an lvalue for aa[key1], i.e. the entry
will be default initialized iff missing.
If the expression is an rvalue though (aa[key1][key2]), a missing
key1 will trigger a range error.
In an opIndex(Key) you have no idea whether the whole expression
I an lvalue or an rvalue.
IIRC the construction/assignment of a value is also handled
specifically.