"H. S. Teoh" <[email protected]> wrote in message news:[email protected]... > On Fri, Mar 23, 2012 at 06:11:05AM +0100, Andrej Mitrovic wrote: > [...] >> Btw, want to see a magic trick? Put this into your hash: >> >> this(AA)(AA aa) >> if (std.traits.isAssociativeArray!AA >> && is(KeyType!AA == keytype) >> && is(ValueType!AA == valuetype)) >> { >> foreach (key, val; aa) >> this[key] = val; >> } >> >> And theeeen..... *drumroll*: >> >> AA!(string,int) bb = cast()["abc":123]; >> >> badoom-tshhh. LOL! > > WAT?! What on earth is "cast()" supposed to mean?? That's just screwed > up. Well anyway, I pushed the change to github, since it at least makes > literal sliiightly more usable. Have fun! :-) >
My guess is that cast forces it to be parsed as an ExpInitializer instead of an ArrayInitializer. Associative array literals as initializers are parsed as array initializers then reinterpreted during semantic. And cast() is like cast(const) or cast(shared).
