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
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
];
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
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
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
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
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
immutable long[string] aa = [
"foo": 5,
"bar": 10,
"baz": 2000
];
... Error: non-constant expression ["foo":5L, "bar":10L,
"baz":2000L]