How to provide this arg or functor for algorithm?

anonymous via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Aug 17 02:51:45 PDT 2015


On Sunday, 16 August 2015 at 23:05:42 UTC, Ali Çehreli wrote:
> // Now the type of d is a template parameter
> @nogc auto func(Func)(uint[] arr, Func d)
> {
>     return arr.map!(d);
> }

Huh. I think func being a template is the key here. When the 
original code is put in a template, it works too (with 2.068):

----
void func()() @nogc
{
     import std.algorithm;
     uint[3] arr = [1,2,3];
     uint context = 2;
     auto r = arr[].map!(delegate(value) { return value * context; 
});
}
void main()
{
     func();
}
----



More information about the Digitalmars-d-learn mailing list