Lambda surprise

Jean-Louis Leroy jl at leroy.nyc
Sun Feb 9 02:58:54 UTC 2020


On Saturday, 8 February 2020 at 13:21:59 UTC, Basile B. wrote:

> ---
> import std.algorithm.iteration, std.range, std.traits, 
> std.functional;
>
> /*>>>*/ static /*<<<*/ template map(fun...)
> if (fun.length >= 1)
> {
>     auto map(Range)(Range r) if (isInputRange!(Unqual!Range))
>     {
>         import std.meta : AliasSeq, staticMap;
>         alias RE = ElementType!(Range);
>         alias _fun = unaryFun!fun;
>         alias _funs = AliasSeq!(_fun);
>         return MapResult!(_fun, Range)(r);
>     }
> }
> ---

Well, this helped a lot. I copied your code to make a 'mapStatic' 
template. I needed to make two fixes, here they are:

---
static template mapStatic(fun...)
if (fun.length >= 1)
{
     auto mapStatic(Range)(Range r)
       if (isInputRange!(std.algorithm.mutation.Unqual!Range)) <-- 
needed fully qualified path
     {
         import std.meta : AliasSeq, staticMap;
         import std.functional : unaryFun; // <-- needed import
         alias RE = ElementType!(Range);
         alias _fun = unaryFun!fun;
         alias _funs = AliasSeq!(_fun);
         return MapResult!(_fun, Range)(r);
     }
}
---


More information about the Digitalmars-d mailing list