Bug 17020 – std.parallelism.taskpool amap should accept lambdas

Status
NEW
Severity
enhancement
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-12-23T01:52:04Z
Last change time
2024-12-01T16:28:58Z
Keywords
bootcamp
Assigned to
No Owner
Creator
Seb
Moved to GitHub: phobos#9702 →

Comments

Comment #0 by greeenify — 2016-12-23T01:52:04Z
void main() { auto w = iota(0,1_000_000); int[] foo; // Not OK, dmd can't infer lambda isn't a delegate // foo = taskPool().amap!(a => a + 1)(w); // OK: foo = taskPool().amap!`a+1`(w); // string lambdas, yeah! foo = taskPool().amap!(function int(int a) => a + 1)(w); static int func(int a) { return a + 1; } foo = taskPool().amap!func(w); } In the forum thread a quick & dirty solution was posted: private auto pmap(alias fun, R)(R range) if(isInputRange!R) { import std.parallelism; import core.sync.mutex; static __gshared Mutex mutex; if(mutex is null) mutex = new Mutex; typeof(fun(range.front))[] values; foreach(i, value; range.parallel) { auto newValue = fun(value); synchronized(mutex) { if(values.length < i + 1) values.length = i + 1; values[i] = newValue; } } return values; } http://forum.dlang.org/post/[email protected]
Comment #1 by robert.schadek — 2024-12-01T16:28:58Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/9702 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB