taskPool.reduce vs algorithm.reduce
Dorian Haglund
dorian.haglund at gmail.com
Wed Jul 11 08:31:30 UTC 2018
Hi.
I'm trying to use taskPool.reduce with a delegate, for example:
import std.parallelism;
int main(string[] args)
{
int f(int a, int b)
{
if (args.length > 1)
return a+b;
else
return a-b;
}
auto res = taskPool.reduce!f([1, 2, 3]);
return 0;
}
But it fails to compile (with gdc 8.1.0, dmd v2.081) complaining
that
template instance reduce!(f) cannot use local 'f' as parameter to
non-global template reduce(functions...)
The snippet above compiles with the reduce function from
std.algorithm.
Is there a way to make the code compile with taskPool.reduce ?
(I don't want to write two functions and choosing one depending
on args.length)
Why the interface difference between std.algorithm's reduce and
taskPool.reduce ?
Best regards,
Dorian
More information about the Digitalmars-d-learn
mailing list