Compile-time associative array
boolangery
eliott.dumeix at gmail.com
Tue Mar 19 08:50:15 UTC 2019
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 ?
More information about the Digitalmars-d-learn
mailing list