When are associative arrays meant to throw a RangeError?

Timon Gehr timon.gehr at gmx.ch
Sat Feb 18 18:07:02 PST 2012


On 02/19/2012 12:40 AM, Andrej Mitrovic wrote:
> 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..

The error is unrelated to your wrapper type.

static assert(!is(typeof(1~1)));

Concatenation only works if at least one of the types is an array.


More information about the Digitalmars-d mailing list