string mixin and alias

Jesse Phillips via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jul 29 11:34:56 PDT 2016


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().


More information about the Digitalmars-d-learn mailing list