parallel foreach

Alex via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon May 1 05:42:01 PDT 2017


Hi all,
the last foreach in the following code does not compile... Is 
this a bug, or is something wrong with my syntax?

void main()
{
	import std.parallelism : parallel;
	import std.range : iota;
	
	foreach(i; iota(0, 5)){}
	foreach(i; staticIota!(0, 5)){}
	foreach(i; parallel(iota(0, 5))){}
	foreach(i; parallel(staticIota!(0, 5))){}
}

// copied from core.internal.traits
template staticIota(int beg, int end)
{
	import std.typetuple;
     static if (beg + 1 >= end)
     {
         static if (beg >= end)
         {
             alias staticIota = TypeTuple!();
         }
         else
         {
             alias staticIota = TypeTuple!(+beg);
         }
     }
     else
     {
         enum mid = beg + (end - beg) / 2;
         alias staticIota = TypeTuple!(staticIota!(beg, mid), 
staticIota!(mid, end));
     }
}


More information about the Digitalmars-d-learn mailing list