template mixins for boilerplate

Paul D Anderson via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jun 21 06:08:01 PDT 2014


On Saturday, 21 June 2014 at 11:12:18 UTC, Artur Skawina via 
Digitalmars-d-learn wrote:
> 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

Beautiful! That's it.

Thanks,

Paul


More information about the Digitalmars-d-learn mailing list