Typed variadic template syntax?
Etienne
etcimon at gmail.com
Thu Jan 30 09:12:51 PST 2014
On 2014-01-30 10:28 AM, Timon Gehr wrote:
> import std.typetuple, std.stdio;
> void main(){
> foreach(i; TypeTuple!(1,2,3)){
> mixin("int num"~i.stringof~";");
> }
> num1=1;
> num2=2;
> num3=3;
> writeln(num1,num2,num3);
> }
>
>
This written as a static foreach or declarative foreach, would be
awesome if it exposed the scope. For now the only solution is to build a
string and mixin the string like this
string fct(R)(){
string str;
foreach (range ; R)
str ~= "int num " ~ range.stringof ~ ";";
return str;
}
mixin(fct!(TypeTuple!(1,2,3));
writeln(num1,num2, num3);
Looks a little less convenient than
static foreach ( i; 0..3 )
mixin("int num" ~ i.stringof ~ ";");
writeln(num1,num2, num3);
More information about the Digitalmars-d
mailing list