foreach ( i; 1 .. n ) and parallel()

H. S. Teoh hsteoh at quickfur.ath.cx
Sat Feb 23 16:11:43 PST 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.


More information about the Digitalmars-d-learn mailing list