digitalmars.D - associative array definition
- llee (6/6) Jul 11 2008 Is it possible to define associative arrays using a format similar to th...
- bearophile (13/14) Jul 11 2008 I suggest you to use the d.learn group for this kind of questions.
Is it possible to define associative arrays using a format similar to that used
to define other types of arrays? For example I can define an integer array
using:
int[] array = [1, 2, 3];
I can define an associative array using:
string [string] array;
array ["key"] = "value;
But I would like to use a static declaration like the one above.
Jul 11 2008
llee:But I would like to use a static declaration like the one above.I suggest you to use the d.learn group for this kind of questions. I think you can't define AAs statically, but you can do something like: string[char] map; static this() { map = ['a':"foo"[], 'b':"bar"]; } the static this() is executed before the main(). ---------------- Note for the other people, static AAs (and static sets, if D will ever have them) can enjoy perfect hashing, this is a recent note of mine: Bye, bearophile
Jul 11 2008








bearophile <bearophileHUGS lycos.com>