www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - foreach ( i; 1 .. n ) and parallel()

reply Lee Braiden <leebraid gmail.com> writes:
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
Feb 23 2013
parent reply "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
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.
Feb 23 2013
parent "bearophile" <bearophileHUGS lycos.com> writes:
H. S. Teoh:

 AFAIK, x..y syntax only works in foreach and in array slicing.
Sadly. Bye, bearophile
Feb 23 2013