private auto _funimpl(string s) { /* what was previously in fun(string) */ }template fun(string s) { enum fun = _funimpl(s); } // usage: fun!("times"); // always executes _funimpl at compile time -Steve
You could even use this template: template ct(alias f) { template ct(params...) { enum ct = f(params); } } to define templates like this: alias ct!((string s) { // function body... }) fun; or with this syntax: alias ct!(a => a * a) pow2;