Hi,

I want to use a constant associative array in a ctfe-able function.

Example:

string ctfeableFunction()
{
    return Foo["foo"];
}

Then I force ctfe with:

enum res = ctfeableFunction();

When I use an enum like:

enum Foo = ["foo" : "bar"];

It works fine.

D-Scanner keep saying to me: This enum may lead to unnecessary allocation at run-time. Use 'static immutable [...] instead'

But it lead to: Error: static variable Foo cannot be read at compile time.

So is the only way to make ctfe-able associative array is to use enum instead of static immutable ?



Reply via email to