Top level associative arrays
ANtlord via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue May 2 21:03:30 PDT 2017
On Tuesday, 2 May 2017 at 16:34:15 UTC, H. S. Teoh wrote:
> On Tue, May 02, 2017 at 02:37:20PM +0000, ANtlord via
> Digitalmars-d-learn wrote:
>> On Tuesday, 2 May 2017 at 12:41:01 UTC, Jacob Carlborg wrote:
>> >
>> > Note that when declared as "enum", all places it's
>> > referenced, a new associative array will be allocated.
>>
>> If it is allocated at all places I can move initialization to
>> module ctor as says evilrat but how can I make an immutable
>> associative array?
>
> Just declare it immutable. The module ctor can still initialize
> it, because ctors are allowed to initialize immutables:
>
> ------
> immutable string[string] dict;
> static this() {
> dict = [
> "abc": "def",
> "ghi": "lmn"
> ];
> }
> void main() {
> import std.stdio;
> writeln(dict["abc"]);
> }
> ------
>
>
> T
Thanks a lot!
More information about the Digitalmars-d-learn
mailing list