digitalmars.D.learn - foreach ( i; 1 .. n ) and parallel()
- Lee Braiden (17/17) Feb 23 2013 Just a quick conceptual question: why doesn't the following work?
- H. S. Teoh (10/23) Feb 23 2013 [...]
- bearophile (4/5) Feb 23 2013 Sadly.
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
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
H. S. Teoh:AFAIK, x..y syntax only works in foreach and in array slicing.Sadly. Bye, bearophile
Feb 23 2013