Understanding alias template parameters

JG someone at somewhere.com
Thu Apr 21 21:02:47 UTC 2022


Hi,

Could someone possibly help me to understand why the commented 
line doesn't compile?


```d
import std;

struct MapResult(R,F)
{
     R r;
     const F f;
     auto empty() { return r.empty; }
     auto front() { return f(r.front); }
     void popFront() { r.popFront; }
     auto save() { return typeof(this)(r.save,f); }
}

auto myMap(alias f, R)(R r) {
     return MapResult!(R,typeof(f))(r,f);
}


void main()
{
    int function(int) f = x=>2*x;
    iota(10).myMap!f.writeln;
    //iota(10).myMap!(x=>2*x).writeln; <--- Why doesn't this 
compile?

}
```

(I do know that Phobos's map works differently with better 
performance).


More information about the Digitalmars-d-learn mailing list