method generation by name

BCS ao at pathlink.com
Mon Jul 23 17:32:26 PDT 2007


Reply to Kirk,

> Building the whole thing as a string is probably the cleanest
> solution:
> 
> template make_func(char[] name) {
> mixin("void "~name~"() {}");
> }
> mixin make_func!("foo");
> 
> void main() {
> foo();
> }
>
> You can get rid of some of the ugliness of this approach by factoring
> out the function's implementation into another function, and calling
> the actual implementation inside the string.
>

that works (well in my case) but still seems hackish 

> Whether the function call overhead is worse than stuffing it all
> inside the string is of course up to you.
> 

In the case I'm thinking of that overhead is a drop in sea.




More information about the Digitalmars-d-learn mailing list