template mixins for boilerplate

Artur Skawina via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jun 21 04:12:05 PDT 2014


On 06/21/14 05:32, Paul D Anderson via Digitalmars-d-learn wrote:
> I can't use a template mixin:
> 
> mixin template Function(string name)
> {
>   const char[] Function =
>     "public static int " ~ name ~ "() { return other.module." ~ name ~"; }";
> }
> 
> Error: mixin templates are not regular templates.

   mixin template Function(string name) {
      mixin("public static int " ~ name ~ "() { return other.module." ~ name ~"; }");
   }

   struct S {
      mixin Function!"fctn1";
   }

artur


More information about the Digitalmars-d-learn mailing list