One more about mixins

Tomasz Sowiñski tomeksowi at gmail.com
Sun Aug 24 16:21:54 PDT 2008


I got a code generating function:

string intGen(string[] names...)
{
    string result;
    foreach (name; names)
        result ~= "int " ~ name ~ "; ";
    return result;
}

void main() {
    writeln(intGen("aa", "bb", "cc"));  // ok, writes "int aa; int bb; int cc; "
}

struct tag {
    mixin(intGen("aa", "bb", "cc"));  // doesn't compile, but why?
}

I tried using a string[] as an argument instead of a variadic argument, but still it doesn't work. I know the compiler must be able to evaluate mixins at compile time and I think it's able to do so in the example.

Tomek


More information about the Digitalmars-d-learn mailing list