Thread overview
foreach ( i; 1 .. n ) and parallel()
Feb 24, 2013
Lee Braiden
Feb 24, 2013
H. S. Teoh
Feb 24, 2013
bearophile
February 24, 2013
Just a quick conceptual question: why doesn't the following work?

foreach(i ; parallel(1 .. 11))
{
    ...
}

I would have expected 1 .. 10 to give me a range, and parallel to work with that.  Does 1 .. 11 ONLY work as part of the foreach() syntax?

If not, is there some sort of range generator helper, like python's range () function, which I can use something like:

r = range(1,11);

foreach( i; parallel(r))
{
    ...
}



Thanks,

-- 
Lee
February 24, 2013
On Sun, Feb 24, 2013 at 12:04:35AM +0000, Lee Braiden wrote:
> Just a quick conceptual question: why doesn't the following work?
> 
> foreach(i ; parallel(1 .. 11))
> {
>     ...
> }
> 
> I would have expected 1 .. 10 to give me a range, and parallel to work with that.  Does 1 .. 11 ONLY work as part of the foreach() syntax?

AFAIK, x..y syntax only works in foreach and in array slicing.


> If not, is there some sort of range generator helper, like python's range () function, which I can use something like:
> 
> r = range(1,11);
[...]

It's std.range.iota:

	foreach (i; parallel(iota(1, 11))) ...

should work.


T

-- 
Help a man when he is in trouble and he will remember you when he is in trouble again.
February 24, 2013
H. S. Teoh:

> AFAIK, x..y syntax only works in foreach and in array slicing.

Sadly.

Bye,
bearophile