allocate an array of AA?

bearophile bearophileHUGS at lycos.com
Sat Mar 8 12:41:16 PST 2008


sa:
> But how to write such 'a creation'? i.e. how to new an AA? what's the syntax?

I think some sugar can be added to the language for this. In the meantime you can use this from my D libs:

/***************************************
Return a new empty associative array of the given KeyType,ValueType.

Example: AA!(int, string);
*/
template AA(KeyType, ValueType) {
    const ValueType[KeyType] AA = AA_impl!(KeyType, ValueType).res;
}

private template AA_impl(KeyType, ValueType) {
    ValueType[KeyType] result;
    const ValueType[KeyType] res = result;
}

to be used as something as:

aaa char[int][];
foreach(_; xrange(10))
    aaa ~= AA!(int, char);

Bye,
bearophile



More information about the Digitalmars-d mailing list