Re: Static initialization of associative arrays

2021-03-11 Thread Imperatorn via Digitalmars-d-learn
On Thursday, 11 March 2021 at 18:41:08 UTC, Ali Çehreli wrote: On 3/11/21 10:06 AM, Chris Piker wrote: >https://dlang.org/spec/hash-map.html#static_initialization > > that this feature is not yet implemented. I use a shared static this() block: immutable string[int] aa; shared static

Re: Static initialization of associative arrays

2021-03-11 Thread Chris Piker via Digitalmars-d-learn
On Thursday, 11 March 2021 at 19:12:34 UTC, H. S. Teoh wrote: On Thu, Mar 11, 2021 at 06:06:35PM +, Chris Piker via immutable int[string] aa; shared static this() { aa = [ "abc": 123, "def": 456, /* ... */ ]; } Hi H.S.T Yes, I'm using static if, but do

Re: Static initialization of associative arrays

2021-03-11 Thread Chris Piker via Digitalmars-d-learn
On Thursday, 11 March 2021 at 18:41:08 UTC, Ali Çehreli wrote: On 3/11/21 10:06 AM, Chris Piker wrote: >https://dlang.org/spec/hash-map.html#static_initialization > > that this feature is not yet implemented. I use a shared static this() block: immutable string[int] aa; shared static

Re: Static initialization of associative arrays

2021-03-11 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 11, 2021 at 06:06:35PM +, Chris Piker via Digitalmars-d-learn wrote: [...] > Today I ran across a situation where an immutable associative array > would be handy. While perusing the language spec I noticed here: > > https://dlang.org/spec/hash-map.html#static_initialization >

Re: Static initialization of associative arrays

2021-03-11 Thread Ali Çehreli via Digitalmars-d-learn
On 3/11/21 10:06 AM, Chris Piker wrote: >https://dlang.org/spec/hash-map.html#static_initialization > > that this feature is not yet implemented. I use a shared static this() block: immutable string[int] aa; shared static this() { aa = [ 1: "one" ]; } void main() { assert(aa.length

Re: static initialization of associative arrays

2009-04-15 Thread novice2
may be you can raplace string with char[] ?

Re: static initialization of associative arrays

2009-04-15 Thread Daniel Keep
Tyro[a.c.edwards] wrote: Is it yet possible to statically initialize an associative array? If so, please point me to the documentation. I am using DMD v2.028. Currently I'm able to do this: import std.stdio; string[string] types; static this(){ types = [ void:void, bool:bool ];

Re: static initialization of associative arrays

2009-04-15 Thread bearophile
Daniel Keep: I think Walter said something a while back to the effect that making it possible to statically initialise AAs isn't feasible because it requires setting up a complex structure on the heap. At the moment you can't statically initialize a built-in AA in D. But with a small change in