d编译时与运行时关联数组
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();
}
浙公网安备 33010602011771号