Error with associative array initializer DMD32 D Compiler v2.070.0
asdf via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Mar 3 02:33:25 PST 2016
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 expressions. :(
This ended up failing too:
struct slot_t { char* key; long value; };
slot_t bogus[3] = {
{ "foo", 5L },
{ "bar", 10L },
{ "baz", 2000L }
};
import std.stdio;
void main() {
bogus.map.writeln();
}
More information about the Digitalmars-d-learn
mailing list