How do I use CTFE to generate an immutable associative array at compile time?

H. S. Teoh via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Feb 21 14:49:36 PST 2017


On Tue, Feb 21, 2017 at 11:50:02PM +0100, Daniel Kozak via Digitalmars-d-learn wrote:
> I have similar issue and I beleive I was able to workaround that
> somehow, but it is so many years now :(. Have you tried enum
> dataLookup instead of immutable string[string] dataLookup

That may appear to work, but I would *strongly* recommend against it,
because what happens when you use enum with an AA, is that the AA will
be created *at runtime*, *every single time* it is referenced.  (It is
as if you copy-n-pasted the entire AA into the code each time you
reference the enum.)  Which will introduce ridiculous amounts of
redundant work at runtime and cause a big performance penalty.


T

-- 
What did the alien say to Schubert? "Take me to your lieder."


More information about the Digitalmars-d-learn mailing list