Using template mixin, with or without mixin ?

biocyberman via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Apr 7 16:47:57 PDT 2017


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;

}


More information about the Digitalmars-d-learn mailing list