Typed variadic template syntax?
Peter Alexander
peter.alexander.au at gmail.com
Wed Jan 29 14:16:55 PST 2014
On Wednesday, 29 January 2014 at 21:18:06 UTC, Etienne wrote:
>>
>> void exec(string command)(){
>> foreach(str ; choice.splitter(".")){
>> writeln(str);
>> }
>> }
>
> I'd like to take the opportunity to say how much I'd love to be
> able to do a static foreach rather than use recursion.
You can use TypeTuple for static foreach.
void foo(int x)()
{
import std.stdio;
writeln(x);
}
void main()
{
import std.typetuple;
foreach (x; TypeTuple!(1, 2, 3))
foo!x();
}
Notice that the loop variable x is used as a template parameter
at compile time. The code expands to:
foo!1();
foo!2();
foo!3();
More information about the Digitalmars-d
mailing list