Static associative array expressions
Stefan Koch
uplink.coder at googlemail.com
Mon Sep 20 13:09:05 UTC 2021
On Monday, 20 September 2021 at 13:02:22 UTC, Steven
Schveighoffer wrote:
> ```d
> struct FakeAA(K, V)
> {
> // mimic the true AA impl
> struct FakeBucket {
> size_t hash;
> void * entry;
> }
> struct FakeAAImpl
> {
> FakeBucket[] buckets;
> uint used;
> uint deleted;
> TypeInfo_Struct entryTI;
> uint firstUsed;
> immutable uint keysz;
> immutable uint valsz;
> immutable uint valoff;
> ubyte flags;
> }
> FakeAAImpl *impl;
> V[K] __get() { return *(cast(V[K]*)&impl); }
> alias __get this;
> }
> ```
>
> And then build that thing at compile time based on the CTFE AA.
>
> But I would still like to see the AA static initializer "just
> work".
>
> -Steve
In fact that is exactly what my implementation of AA literals
does.
just that it does that internally to the "static initializer
generation code"
except for evaluation of the hash-function it has nothing to do
with CTFE ;)
And by the by that is _exactly_ how _all_ generation of static
initalizers work.
They build up "fake" runtime structures and hope that the
structures match the layout used at runtime.
Which is why cross-compilation is still a pain.
More information about the Digitalmars-d
mailing list