www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Initializing associative arrays

reply Chris Stevenson <Chris_member pathlink.com> writes:
Does D provide a way to initial;ize an associative array?  I want to use a
static const associative array in a class.  I'm beginning to think I'll have to
drop the const part and use a static initializer instead.

--Chris Stevenson
Aug 18 2004
next sibling parent reply Ilya Minkov <minkov cs.tum.edu> writes:
Chris Stevenson schrieb:

 Does D provide a way to initial;ize an associative array?  I want to use a
 static const associative array in a class.  I'm beginning to think I'll have to
 drop the const part and use a static initializer instead.
Unfortunately, currently there are no associative array literals. Thus you won't be able to create a constant associative array. Walter hasn't expressed his mind on it, although there were a number of proposals. -eye
Aug 18 2004
next sibling parent Arcane Jill <Arcane_member pathlink.com> writes:
In article <cfvd5q$2b60$1 digitaldaemon.com>, Ilya Minkov says...
Chris Stevenson schrieb:

 Does D provide a way to initial;ize an associative array?  I want to use a
 static const associative array in a class.  I'm beginning to think I'll have to
 drop the const part and use a static initializer instead.
Unfortunately, currently there are no associative array literals. Thus you won't be able to create a constant associative array. Walter hasn't expressed his mind on it, although there were a number of proposals.
I have considered before the notion of cobbling one together with some inline assembler (or, more likely, writing a tool to automate such an asm block), but there's one small problem - from the D Manual page "Application Binary Interface":
 Associative Arrays
 TBD
Bah! I would like to know when this small piece of documentation could be completed. Arcane Jill
Aug 18 2004
prev sibling parent Sha Chancellor <schancel pacific.net> writes:
In article <cfvd5q$2b60$1 digitaldaemon.com>,
 Ilya Minkov <minkov cs.tum.edu> wrote:

 Chris Stevenson schrieb:
 
 Does D provide a way to initial;ize an associative array?  I want to use a
 static const associative array in a class.  I'm beginning to think I'll 
 have to
 drop the const part and use a static initializer instead.
Unfortunately, currently there are no associative array literals. Thus you won't be able to create a constant associative array. Walter hasn't expressed his mind on it, although there were a number of proposals. -eye
int[3] a = [ 1:2, 3 ]; // a[0] = 0, a[1] = 2, a[2] = 3 This is most handy when the array indices are given by enums: enum Color { red, blue, green }; int value[Color.max] = [ blue:6, green:2, red:5 ]; The logical jump for me would be: int[char[]] foo = [ "joe":5, "fran":10, "bob":20 ]; However, I don't think it's currently implemented.
Aug 18 2004
prev sibling parent Stewart Gordon <smjg_1998 yahoo.com> writes:
Chris Stevenson wrote:

 Does D provide a way to initial;ize an associative array?  I want to use a
 static const associative array in a class.  I'm beginning to think I'll have to
 drop the const part and use a static initializer instead.
Been an issue for a while. http://www.digitalmars.com/drn-bin/wwwnews?D/26695 Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on on the 'group where everyone may benefit.
Aug 22 2004