non-constant expression ["foo":5, "bar":10, "baz":2000]
bauss
jj_1337 at live.dk
Fri Jan 7 07:32:12 UTC 2022
On Thursday, 6 January 2022 at 16:01:40 UTC, HuskyNator wrote:
> On Thursday, 6 January 2022 at 13:33:24 UTC, bauss wrote:
>> While not the exact same, there's a small work around here
>> that can help in some cases:
>>
>> ```d
>> immutable long[string] aa;
>> shared static this() {
>> aa = [
>> "foo": 5,
>> "bar": 10,
>> "baz": 2000
>> ];
>> }
>> ```
>
> Thanks a lot!
> I've tried it with static this() earlier, but the shared part
> fixes it for me.
The reason why it needs to be shared is because it's only
executed once, where as just static this is executed for each
thread.
More information about the Digitalmars-d-learn
mailing list