Bug 17019 – std.algorithm.iteration.each should be usable with parallel

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2016-12-23T01:24:16Z
Last change time
2018-08-14T19:20:02Z
Keywords
bootcamp
Assigned to
No Owner
Creator
Seb

Comments

Comment #0 by greeenify — 2016-12-23T01:24:16Z
The following test fails: ``` unittest { import std.algorithm.iteration : each, sum; import std.parallelism : parallel; import std.range : iota; auto logsIndex = new int[10]; parallel(logsIndex).each!((i, ref e) => e += i); assert(logsIndex.sum == 10.iota.sum); } ``` while it passes without parallel: ``` unittest { import std.algorithm.iteration : each, sum; import std.parallelism : parallel; import std.range : iota; auto logsIndex = new int[10]; logsIndex.each!((i, ref e) => e += i); assert(logsIndex.sum == 10.iota.sum); } ``` of course the foreach alternative works as well ``` unittest { import std.algorithm.iteration : sum; import std.parallelism : parallel; import std.range : iota; auto logsIndex = new int[10]; foreach (i, ref e; parallel(logsIndex)) e += i; assert(logsIndex.sum == 10.iota.sum); } ``` /usr/include/dlang/dmd/std/algorithm/iteration.d(936): Error: template foo.__unittestL1_3.__lambda1 cannot deduce function from argument types !()(int), candidates are: foo.d(8): foo.__unittestL1_3.__lambda1 foo.d(8): Error: template instance foo.__unittestL1_3.each!((i, ref e) => e += i).each!(ParallelForeach!(int[])) error instantiating Failed: ["dmd", "-unittest", "-g", "-v", "-c", "-of/tmp/.rdmd-1000/rdmd-foo.d-2E6138563669BF9753765C098C72200E/objs/foo.o", "foo.d", "-I.", "/tmp/.rdmd-1000/stubmain.d"] This is probably related to https://issues.dlang.org/show_bug.cgi?id=15357
Comment #1 by github-bugzilla — 2018-08-14T19:20:01Z
Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/3f44a4cd73a2c6423d4a49e3354b02a4acac2dfe Fix issue 17019 - std.algorithm.iteration.each should be usable with parallel https://github.com/dlang/phobos/commit/bb769cfaf51f32a9f20567f885361fe828e9f8a3 Merge pull request #4990 from wilzbach/fix-15357-each-foreach Fix issue 17019: `each` should be usable with parallel (and behave like foreach) merged-on-behalf-of: Andrei Alexandrescu <[email protected]>