Get Function Body

bauss via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jun 30 09:38:45 PDT 2017


Is there a way to retrieve the body of a function as a string?

Scenario.

I want to pass a function to a mixin template and just mixin the 
body of the function.

Ex.

mixin template Foo(alias fun) {
     void bar() {
         mixin(getBodyOfFun(fun));
     }
}

I'm aware that I can pass a string like mixin Foo!"a > b" but I 
would really like to avoid that.

I also can't just call "fun" as normal, unless it can be forced 
to be inline within the mixin template. The reason is if I mixin 
two mixin templates with the same function passed it must exist 
as two different function bodies executed, even tho they do the 
same.

Which means the following must have two "different" baz and not 
the actual baz.

void baz() { ... }

mixin Foo!baz;
mixin Foo!baz;

I don't know if it'll be possible without some sort of "parsing" 
the function or even without "string function bodies".


More information about the Digitalmars-d-learn mailing list