Re: Error with associative array initializer DMD32 D Compiler v2.070.0

2016-03-03 Thread Ali Çehreli via Digitalmars-d-learn
On 03/03/2016 05:17 AM, Andrew Edwards wrote: > On 3/3/16 7:01 PM, MGW wrote: >> immutable long[string] aa = [ >> "foo": 5, >> "bar": 10, >> "baz": 2000 >> ]; > > The only way this can be done outside the body of a function is if it is > a manifest constant. This works: > > enum long[s

Re: Error with associative array initializer DMD32 D Compiler v2.070.0

2016-03-03 Thread Andrew Edwards via Digitalmars-d-learn
On 3/3/16 7:01 PM, MGW wrote: immutable long[string] aa = [ "foo": 5, "bar": 10, "baz": 2000 ]; The only way this can be done outside the body of a function is if it is a manifest constant. This works: enum long[string] aa = [ "foo": 5, "bar": 10, "baz": 2000 ];

Re: Error with associative array initializer DMD32 D Compiler v2.070.0

2016-03-03 Thread mahdi via Digitalmars-d-learn
On Thursday, 3 March 2016 at 10:35:50 UTC, MGW wrote: The citation from https://dlang.org/spec/hash-map.html Static Initialization of AAs immutable long[string] aa = [ "foo": 5, "bar": 10, "baz": 2000 ]; unittest { assert(aa["foo"] == 5); assert(aa["b

Re: Error with associative array initializer DMD32 D Compiler v2.070.0

2016-03-03 Thread asdf via Digitalmars-d-learn
On Thursday, 3 March 2016 at 10:35:50 UTC, MGW wrote: The citation from https://dlang.org/spec/hash-map.html Static Initialization of AAs immutable long[string] aa = [ "foo": 5, "bar": 10, "baz": 2000 ]; unittest { assert(aa["foo"] == 5); assert(aa["b

Re: Error with associative array initializer DMD32 D Compiler v2.070.0

2016-03-03 Thread MGW via Digitalmars-d-learn
The citation from https://dlang.org/spec/hash-map.html Static Initialization of AAs immutable long[string] aa = [ "foo": 5, "bar": 10, "baz": 2000 ]; unittest { assert(aa["foo"] == 5); assert(aa["bar"] == 10); assert(aa["baz"] == 2000); } Judging

Re: Error with associative array initializer DMD32 D Compiler v2.070.0

2016-03-03 Thread asdf via Digitalmars-d-learn
On Thursday, 3 March 2016 at 10:01:47 UTC, MGW wrote: immutable long[string] aa = [ "foo": 5, "bar": 10, "baz": 2000 ]; ... Error: non-constant expression ["foo":5L, "bar":10L, "baz":2000L] D associative arrays are a dynamic runtime feature, thus can't be initialized without runtime

Re: Error with associative array initializer DMD32 D Compiler v2.070.0

2016-03-03 Thread Anonymouse via Digitalmars-d-learn
On Thursday, 3 March 2016 at 10:01:47 UTC, MGW wrote: immutable long[string] aa = [ "foo": 5, "bar": 10, "baz": 2000 ]; ... Error: non-constant expression ["foo":5L, "bar":10L, "baz":2000L] I'm not sure there's a way around this except by initialising it at runtime. So you can't get

Error with associative array initializer DMD32 D Compiler v2.070.0

2016-03-03 Thread MGW via Digitalmars-d-learn
immutable long[string] aa = [ "foo": 5, "bar": 10, "baz": 2000 ]; ... Error: non-constant expression ["foo":5L, "bar":10L, "baz":2000L]