Wrong lowering for a[b][c]++
H. S. Teoh
hsteoh at quickfur.ath.cx
Thu Mar 22 14:07:31 PDT 2012
On Thu, Mar 22, 2012 at 07:55:09PM +0100, Andrej Mitrovic wrote:
[...]
> Hmm, what about (temporary) compatibility with hash literals? You
> could add the following to the newAA module:
>
> static import std.traits;
> template KeyType(V : V[K], K)
> {
> alias K KeyType;
> }
>
> template ValueType(V : V[K], K)
> {
> alias V ValueType;
> }
Done, pushed to github.
> and in the AssociativeArray struct:
> void opAssign(AA)(AA aa)
> if (std.traits.isAssociativeArray!AA
> && is(KeyType!AA == keytype)
> && is(ValueType!AA == valuetype))
> {
> foreach (key, val; aa)
> this[key] = val;
> }
Done, though this required another opAssign() to replace the default one
that got suppressed by this template. Which required some nasty const
casts to work properly, but at least D lets you do that when you need
to. :-)
> Then this will work:
>
> AA!(int, string) intToStr;
> intToStr = [1:"foo"];
> assert(intToStr[1] == "foo");
>
> Otherwise it will be pretty hard to test the new hashes without
> changing a significant amount of code.
True. I still can't get this to work though:
AA!(string,int) aa = ["abc":123];
Maybe this needs a ctor?
T
--
Almost all proofs have bugs, but almost all theorems are true. -- Paul Pedersen
More information about the Digitalmars-d
mailing list