Static Initialization of AAs - when?
Steven Schveighoffer
schveiguy at gmail.com
Sun May 29 15:34:09 UTC 2022
On 5/28/22 8:36 PM, arandomonlooker wrote:
> Hello.
> I am posting here for the first time as a beginner to the D programming
> language.
> I was curious about the fact that static initialization of associative
> arrays, while being present in the specification, it has not yet been
> implemented in the language.
> There is a plan to implement it in the future?
> Thank you all in advance.
You can do this with my [newaa
project](https://code.dlang.org/packages/newaa):
```d
import schlib.newaa;
auto myAA = Hash!(string, int)(["hello" : 1, "world" : 2]);
void main()
{
int[string] aa = myAA.asAA;
writeln(aa);
}
```
Not much niceties there yet, notably, it doesn't print out well, or have
a good factory function. You also cannot reinterpret as a builtin AA at
compile time, because the reinterpret cast isn't possible.
But you can just use it as a drop-in replacement for builtin AAs. It
actually is binary compatible, so you can have both a normal builtin AA
reference to it, and a `Hash` reference, and both will work.
-Steve
More information about the Digitalmars-d
mailing list