digitalmars.D.learn - alias with lambda syntax: alias fun2=a=>fun(a);
- Timothee Cour via Digitalmars-d-learn (14/14) Jun 04 2014 Is there a way to do this?
- timotheecour (3/19) Jun 05 2014 ok I remembered we can use std.typetuple.Alias for that.
- Meta (2/3) Jun 05 2014 Or std.functional.unaryFun.
Is there a way to do this? import std.algorithm; auto fun(T)(T a){return a;} template fun2(T){auto fun2(T a){return fun(a);}}//OK but heavy syntax and cannot be nested inside test() void main(){ //alias fun2=fun!int; //OK but needs to specify template params //none of those work: //alias fun2=a=>fun(a); //alias fun2(T)=(T a)=>fun(a); //alias fun2(T)=(T a){return fun(a);} auto b=[1].map!fun2; assert(b.equal([1])); }
Jun 04 2014
On Thursday, 5 June 2014 at 06:58:50 UTC, Timothee Cour via Digitalmars-d-learn wrote:Is there a way to do this? import std.algorithm; auto fun(T)(T a){return a;} template fun2(T){auto fun2(T a){return fun(a);}}//OK but heavy syntax and cannot be nested inside test() void main(){ //alias fun2=fun!int; //OK but needs to specify template params //none of those work: //alias fun2=a=>fun(a); //alias fun2(T)=(T a)=>fun(a); //alias fun2(T)=(T a){return fun(a);} auto b=[1].map!fun2; assert(b.equal([1])); }ok I remembered we can use std.typetuple.Alias for that.
Jun 05 2014
On Thursday, 5 June 2014 at 07:19:07 UTC, timotheecour wrote:ok I remembered we can use std.typetuple.Alias for that.Or std.functional.unaryFun.
Jun 05 2014