How to provide this arg or functor for algorithm?

cym13 via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Aug 16 05:04:50 PDT 2015


On Sunday, 16 August 2015 at 11:53:42 UTC, FreeSlave wrote:
> Let's say I want to map some range using some context.
> The obvious way is to do:
>
> uint[3] arr = [1,2,3];
> uint context = 2;
> auto r = arr[].map!(delegate(value) { return value * context; 
> });

To me the obvious way is to use a lambda, not a delegate:

     uint[3] arr = [1,2,3];
     uint context = 2;
     auto r = arr[].map!(value => value * context);


More information about the Digitalmars-d-learn mailing list