Compile-time associative array
Bastiaan Veelo
Bastiaan at Veelo.net
Wed Mar 20 09:07:00 UTC 2019
On Wednesday, 20 March 2019 at 08:11:27 UTC, boolangery wrote:
> Got it ! Thank you, so I need to write:
>
> enum string[string] CtfeFoo = ["foo" : "bar"];
> static immutable string[string] Foo;
>
> static this()
> {
> Foo = CtfeFoo;
> }
>
> string ctfeableFunction()
> {
> if (__ctfe)
> return CtfeFoo["foo"];
> else
> return Foo["foo"];
> }
>
> void main()
> {
> enum a = ctfeableFunction();
> auto b = ctfeableFunction();
> }
Yes, that looks correct to me.
More information about the Digitalmars-d-learn
mailing list