Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
August 18, 2004 Initializing associative arrays | ||||
---|---|---|---|---|
| ||||
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 |
August 18, 2004 Re: Initializing associative arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chris Stevenson | 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
|
August 18, 2004 Re: Initializing associative arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ilya Minkov | 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 |
August 18, 2004 Re: Initializing associative arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ilya Minkov | 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. |
August 22, 2004 Re: Initializing associative arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chris Stevenson | 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. |
Copyright © 1999-2021 by the D Language Foundation