why mixin template can not inclulde statement;

Radu void at null.pt
Fri Aug 10 13:10:05 UTC 2018


On Friday, 10 August 2018 at 13:05:24 UTC, Kagamin wrote:
> Mixim template can only introduce declarations, not statements, 
> a workaround is a lambda called in place.
>
> mixin template test(A...){
>         __gshared a = A;
>         int dummy = (){ a++; return 0; }();
> }
>
> extern(C) void main(){
>         mixin test!123;
> }

Except that you can't use tuples for that, a working sample:

mixin template test(alias A){
         __gshared a = A;
         int dummy = (){ a++; return 0; }();
}

extern(C) void main(){
     mixin test!123;

     import core.stdc.stdio;
     printf("%d", a);
}


More information about the Digitalmars-d-learn mailing list