On 04/07/2017 04:47 PM, biocyberman wrote:
I want to use mixin to generate function in-place. In template
declaration, I can see 'mixin' keyword is optional. Is it true? What is
the difference and when I must use one way over another?
This is my program:
// This works with and without 'mixin' attribute.
mixin template funcgen(T, U){
T func1(string pr2){
writeln("Func1: ", pr2);
}
U func2(string pr3){
writeln("Func2: ", pr3);
}
}
int main(string[] args){
mixin funcgen!(void, void);
func1("func1");
func2("func2");
return 0;
}
The difference is that you can't use funcgen as a regular template:
funcgen!(void, void);
Error: template instance funcgen!(void, void) mixin templates are not
regular templates
I think it's good practice to use 'mixin template' if it's intended to
be so.
Ali