Revamping associative arrays
bearophile
bearophileHUGS at lycos.com
Sun Oct 18 01:29:57 PDT 2009
Max Samukha:
> I agree. But the problem is the lack of a decent way to instantiate an
> empty AA. Now you either have to do idiotic things like:
>
> int[int] a;
> a[1] = 1;
> a.remove(1);
>
> Or wrap the array in another type.
This is an empty AA, you need nothing else:
int[int] a;
In my post I have also said I'd like to have a built-in expression literal for empty AA, I use this in my dlibs:
private template AA_impl(KeyType, ValueType) {
ValueType[KeyType] result;
const ValueType[KeyType] res = result;
}
template AA(KeyType, ValueType) {
const ValueType[KeyType] AA = AA_impl!(KeyType, ValueType).res;
}
That you can use for example like this, to give an empty AA to a foo() function:
foo(AA!(int, float));
Something built-in with a better syntax may be found, example:
That can be used like:
foo([int:float]);
Bye,
bearophile
More information about the Digitalmars-d
mailing list