When are associative arrays meant to throw a RangeError?

Andrej Mitrovic andrej.mitrovich at gmail.com
Sat Feb 18 15:40:29 PST 2012

On 2/19/12, Andrej Mitrovic <andrej.mitrovich at gmail.com> wrote:
> Chunk[] tempVar = chunks.get("CCCC", null) ~ new Chunk();

I've tried making a wrapper type that does this behind the scenes but
it won't work:

struct Hash(Key, Val)
    Val[Key] aa;

    Val opIndex(Key key)
        return aa.get(key, Val.init);

    alias aa this;

class Chunk { }
alias Hash!(string, Chunk) ChunkHash;

void main()
    ChunkHash chunks;
    Chunk[] tempVar = chunks["CCCC"] ~ new Chunk();

test.d(20): Error: incompatible types for ((chunks.opIndex("CCCC")) ~
(new Chunk)): 'test.Chunk' and 'test.Chunk'

Very odd..

More information about the Digitalmars-d mailing list