July 11, 2008 associative array definition | ||||
|---|---|---|---|---|
| ||||
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.
| ||||
July 11, 2008 Re: associative array definition | ||||
|---|---|---|---|---|
| ||||
Posted in reply to llee | 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: http://groups.google.com/group/comp.lang.python/browse_thread/thread/09363c0d50a804bb# Bye, bearophile | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply