Typed variadic template syntax?
deadalnix
deadalnix at gmail.com
Thu Jan 30 15:06:35 PST 2014
On Thursday, 30 January 2014 at 11:19:33 UTC, Idan Arye wrote:
> Two problems:
>
> 1) You can't use `foreach` outside functions. That means that
> you write:
> struct Foo{
> foreach(i;TypeTuple!(1,2,3)){
> mixin("int num"~i.stringof~";");
> }
> }
>
mixin({ foreach(...) { ... } }())
> 2) `foreach` creates it's own scope. This won't work:
> foreach(i; TypeTuple!(1,2,3)){
> mixin("int num"~i.stringof~";");
> }
> num1=1;
> num2=2;
> num3=3;
> writeln(num1,num2,num3);
You got to mixin the whole stuff, not field by field, and you
won't have any issue.
More information about the Digitalmars-d
mailing list