More magical AA semantics
monarch_dodra
monarchdodra at gmail.com
Fri Jan 11 03:14:27 PST 2013
On Friday, 11 January 2013 at 09:50:18 UTC, deadalnix wrote:
> On Friday, 11 January 2013 at 08:55:55 UTC, Bernard Helyer
> wrote:
>> I completely agree. Doesn't the spec say that relying on
>> the order of assignment evaluation is undefined?
>
> After a long discussion with Andrei, it seems that it is left
> to right.
This seems wrong to me.
In particular, if you define an opIndexAssign, then the RHS *has*
to be evaluated first (from a "visual" point of view, since LHS
is pretty much "this").
//----
a[0] = a[0]
//----
Becomes
//----
a.opIndexAssign(a[0], 0);
//----
On a related note, I don't know how AA's are actually
implemented, but it sounds like giving them opIndexXXX would
solve a lot of our problems:
* Initialization to T.init if RHS throws
* a[0] = a[0]; runs if there is no a[0].
Or even code such as this:
//----
int[int] a;
++a[0];
//----
In what universe do we actually expect this to work? It shouldn't.
More information about the Digitalmars-d
mailing list