Re: each! vs foreach parallel timings
On 12/27/2015 04:17 PM, Jay Norwood wrote: On Sunday, 27 December 2015 at 23:42:57 UTC, Ali Çehreli wrote: That does not compile because i is size_t but apply_metrics() takes an int. One solution is to call to!int: foreach( i, ref a; parallel(samples[])){ apply_metrics(i.to!int,a);} It builds for me still, and executes ok, but must be because size_t and i are both 32 bits on Win32 build. Makes sense. I would still prefer size_t and even leave it out for the lambda: void apply_metrics(size_t i,ref S s){ // ... sn = i.to!int; // ... samples[].each!((i, ref a)=>apply_metrics(i,a)); Ali
Re: each! vs foreach parallel timings
On Sunday, 27 December 2015 at 23:42:57 UTC, Ali Çehreli wrote: On 12/27/2015 11:30 AM, Jay Norwood wrote: > samples[].each!((int i, ref a)=>apply_metrics(i,a)); Are you using an older compiler? That tuple expansion does not work any more at least with dmd v2.069.0 but you can use enumerate(): samples[].enumerate.each!(t=>apply_metrics(t[0].to!int,t[1])); > foreach( i, ref a; parallel(samples[])){ apply_metrics(i,a);} That does not compile because i is size_t but apply_metrics() takes an int. One solution is to call to!int: foreach( i, ref a; parallel(samples[])){ apply_metrics(i.to!int,a);} To not answer your actual question, I don't think it's possible. :) Ali The code I posted was compiled with v2.069.2. It isn't creating a tuple return value in this code. I'll re-check it.
Re: each! vs foreach parallel timings
On Sunday, 27 December 2015 at 23:42:57 UTC, Ali Çehreli wrote: That does not compile because i is size_t but apply_metrics() takes an int. One solution is to call to!int: foreach( i, ref a; parallel(samples[])){ apply_metrics(i.to!int,a);} It builds for me still, and executes ok, but must be because size_t and i are both 32 bits on Win32 build.
Re: each! vs foreach parallel timings
On 12/27/2015 11:30 AM, Jay Norwood wrote: > samples[].each!((int i, ref a)=>apply_metrics(i,a)); Are you using an older compiler? That tuple expansion does not work any more at least with dmd v2.069.0 but you can use enumerate(): samples[].enumerate.each!(t=>apply_metrics(t[0].to!int,t[1])); > foreach( i, ref a; parallel(samples[])){ apply_metrics(i,a);} That does not compile because i is size_t but apply_metrics() takes an int. One solution is to call to!int: foreach( i, ref a; parallel(samples[])){ apply_metrics(i.to!int,a);} To not answer your actual question, I don't think it's possible. :) Ali