Why is amap implemented as a member function of TaskPool?

Jared via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Sep 18 13:51:28 PDT 2014


On Thursday, 18 September 2014 at 19:49:00 UTC, Atila Neves wrote:
> Or what I really want to ask: why can't I call amap from 
> std.parallelism with a lambda? I assume it's because it's a 
> member function but I'm not 100% sure.
>
> Atila

You have to tell DMD that the lambda is not in fact a delegate.

import std.stdio;
import std.range;
import std.parallelism;

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);
}



More information about the Digitalmars-d-learn mailing list