digitalmars.D.learn - Associative Arrays - Initialize via [ value, value, ...] ?
- AEon (15/15) Mar 27 2005 Is there some way to initialize Associative Arrays via "lists"?
- Regan Heath (8/22) Mar 27 2005 Not yet, but hopefully one day we will be able to say something like:
-
Stewart Gordon
(12/16)
Apr 03 2005
- Regan Heath (8/21) Apr 03 2005 I'm not sure either makes any sense.. I was just throwing the idea out
Is there some way to initialize Associative Arrays via "lists"? For a static array: static char[][] month = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]; will work fine, but for static int[char[]] Month = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]; it will not... Is there some way to avoid having to do a "manual" feed via: static int[char[]] Month; Month["Jan"] = 0; Month["Feb"] = 1; etc. in a foreach loop? AEon
Mar 27 2005
On Sun, 27 Mar 2005 18:54:07 +0200, AEon <aeon2001 lycos.de> wrote:Is there some way to initialize Associative Arrays via "lists"? For a static array: static char[][] month = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]; will work fine, but for static int[char[]] Month = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]; it will not... Is there some way to avoid having to do a "manual" feed via: static int[char[]] Month; Month["Jan"] = 0; Month["Feb"] = 1; etc. in a foreach loop?Not yet, but hopefully one day we will be able to say something like: static int[char[]] Month = [ "Jan", "Feb", "Mar" ..etc.. //meaning an associative array with the defined keys, and default values static int[char[]] Month = [ "Jan":1, "Feb":2, "Mar":3, ..etc.. //meaning an associative array with the defined keys, and defined values or even a mixture of the two. Regan
Mar 27 2005
Regan Heath wrote: <snip>Not yet, but hopefully one day we will be able to say something like: static int[char[]] Month = [ "Jan", "Feb", "Mar" ..etc.. //meaning an associative array with the defined keys, and default values<snip> Why not the defined values and default keys, which would make it consistent with static initalisers on linear arrays? Moreover, by "default values" do you mean the default initialiser for the value type, or what? Whichever way, it seems a crocky syntax, and I'd go for requiring AA initialisers to use explicit key:value pairs. Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on on the 'group where everyone may benefit.
Apr 03 2005
On Sun, 03 Apr 2005 17:46:22 +0100, Stewart Gordon <smjg_1998 yahoo.com> wrote:Regan Heath wrote: <snip>I'm not sure either makes any sense.. I was just throwing the idea out there.Not yet, but hopefully one day we will be able to say something like: static int[char[]] Month = [ "Jan", "Feb", "Mar" ..etc.. //meaning an associative array with the defined keys, and default values<snip> Why not the defined values and default keys, which would make it consistent with static initalisers on linear arrays?Moreover, by "default values" do you mean the default initialiser for the value type, or what?Yep.Whichever way, it seems a crocky syntaxAgreed., and I'd go for requiring AA initialisers to use explicit key:value pairs.Yeah. Probably the only way that makes any sense. Regan
Apr 03 2005