Dynamic associative array, to hold many values per key

Logesh Pillay lp at webafrica.org.za
Sun Oct 20 07:10:51 PDT 2013


On Sunday, 20 October 2013 at 13:57:27 UTC, Andrej Mitrovic wrote:
> On Sunday, 20 October 2013 at 13:54:48 UTC, Logesh Pillay wrote:
>> I want an associative array in d programming language. The key 
>> is a struct with two shorts. Easy so far.
>>
>> struct kie { short a; short b; }
>> short[kie] possibles;
>>
>> Problem is I want to hold more than value per key. Dynamic 
>> would be useful so it can grow and shrink per key When I try 
>> to allocate a dynamic array as value to a to key i.e
>>
>> short[] temp; ... possibles[k] = temp;
>>
>> I get the understandable error.  Error: cannot append type 
>> short[] to type short
>>
>> How do I declare an associative array where the values can be 
>> a dynamic array of numbers?
>
> Try:
>
> short[][kie];

Thanks, that worked.


More information about the Digitalmars-d-learn mailing list