D won't let you hide the mixin, the keyword is there specifically to indicate code is being injected in that location.

This isn't what you are looking for, but you can do something like this:

-------------
    string generateCode(string s){return "";}

    void main()
    {
        enum s = "a = 2 + 3; b = 4 + a;";
        foo!(s);
    }

    void foo(alias s)() {
        mixin(generateCode(s));
    }
-------------

Here the generateCode() is mixed in to the context of foo(), which is fine if your code is performing actions but is no good if you're creating declarations that you want to use in the context of main().

Reply via email to