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.

Reply via email to