template mixins for boilerplate

Dicebot via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jun 21 13:31:46 PDT 2014


Apart from what Artur has mentioned template mixins also give you 
opportunity to do qualified injection in case generated symbols 
conflict with existing ones:

class A
{
     void foo() {}
     mixin("void foo() {}"); // error, need to add manual 
"namespace" wrapper
     mixin func!"foo" Sub; // does this out of the box
}

It also slightly improves error messages because semantic 
analysis of generated code is done in template declaration 
context as opposed to whole aggregate.

In general it is pretty good styling rule to follow by default 
even if it does not make any real difference in simple cases like 
this one.


More information about the Digitalmars-d-learn mailing list