Thread overview | |||||
---|---|---|---|---|---|
|
February 24, 2013 foreach ( i; 1 .. n ) and parallel() | ||||
---|---|---|---|---|
| ||||
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 Re: foreach ( i; 1 .. n ) and parallel() | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lee Braiden | 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 Re: foreach ( i; 1 .. n ) and parallel() | ||||
---|---|---|---|---|
| ||||
Posted in reply to H. S. Teoh | H. S. Teoh:
> AFAIK, x..y syntax only works in foreach and in array slicing.
Sadly.
Bye,
bearophile
|
Copyright © 1999-2021 by the D Language Foundation