Re: Compile-time associative array

2019-03-20 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/20/19 4:11 AM, boolangery wrote: On Tuesday, 19 March 2019 at 23:41:58 UTC, Steven Schveighoffer wrote: On 3/19/19 7:22 PM, Bastiaan Veelo wrote: Beware that a CT AA stores its elements in a different order than a RT AA, which you would notice in a foreach, for example. Yes, this is the

Re: Compile-time associative array

2019-03-20 Thread Bastiaan Veelo via Digitalmars-d-learn
On Wednesday, 20 March 2019 at 08:11:27 UTC, boolangery wrote: Got it ! Thank you, so I need to write: enum string[string] CtfeFoo = ["foo" : "bar"]; static immutable string[string] Foo; static this() { Foo = CtfeFoo; } string ctfeableFunction() { if (__ctfe) return CtfeFoo["fo

Re: Compile-time associative array

2019-03-20 Thread boolangery via Digitalmars-d-learn
On Tuesday, 19 March 2019 at 23:41:58 UTC, Steven Schveighoffer wrote: On 3/19/19 7:22 PM, Bastiaan Veelo wrote: Beware that a CT AA stores its elements in a different order than a RT AA, which you would notice in a foreach, for example. Yes, this is the issue -- the runtime AA depends on dru

Re: Compile-time associative array

2019-03-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/19/19 7:22 PM, Bastiaan Veelo wrote: Beware that a CT AA stores its elements in a different order than a RT AA, which you would notice in a foreach, for example. Yes, this is the issue -- the runtime AA depends on druntime, which is not available to the compiler. The compiler has its own

Re: Compile-time associative array

2019-03-19 Thread Bastiaan Veelo via Digitalmars-d-learn
On Tuesday, 19 March 2019 at 08:50:15 UTC, boolangery wrote: Hi, I want to use a constant associative array in a ctfe-able function. Example: string ctfeableFunction() { return Foo["foo"]; } Then I force ctfe with: enum res = ctfeableFunction(); When I use an enum like: enum Foo = ["

Compile-time associative array

2019-03-19 Thread boolangery via Digitalmars-d-learn
Hi, I want to use a constant associative array in a ctfe-able function. Example: string ctfeableFunction() { return Foo["foo"]; } Then I force ctfe with: enum res = ctfeableFunction(); When I use an enum like: enum Foo = ["foo" : "bar"]; It works fine. D-Scanner keep saying to me: T