D2.056
void f(string[] names...)
{
foreach (name; names)
{
mixin("string " ~ name ~ " = name;");
}
}
int main()
{
f("a", "b");
return 0;
}
Why does this not work? It complains about ‘name’ not being compile-time readable, but that is a false statement. The content of ‘names’ is known at compile-time, since it is {“a”, “b”};
I am trying to make a bind with a library, and the passed function names must be defined and pointed to the library.
Functions must be valid for both compilation and compile-time execution. Obviously
fis not compilable.Depending on what you’re trying to achieve, you could either make
namesa template argument (which would make theforeachstatic), or makefbuild a string and mixin the result atf‘s call site.