alias with lambda syntax: alias fun2=a=fun(a);
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])); }
Re: alias with lambda syntax: alias fun2=a=fun(a);
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.
Re: alias with lambda syntax: alias fun2=a=fun(a);
ok I remembered we can use std.typetuple.Alias for that. On Wed, Jun 4, 2014 at 11:58 PM, Timothee Cour thelastmamm...@gmail.com 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])); }
Re: alias with lambda syntax: alias fun2=a=fun(a);
On 06/05/14 08:58, Timothee Cour via Digitalmars-d-learn wrote: Is there a way to do this? 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() alias fun2(T) = fun!T; But this will prevent IFTI, so you'd either need to use 'fun2!int' or introduce another alias ... void main(){ //alias fun2=fun!int; //OK but needs to specify template params ... like this one. If you want the params inferred, then static auto ref fun2(A...)(A a) { return fun(a); } will mostly work. [1] //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])); } artur [1] no perfect forwarding; there's no terse way to do that in D.
Re: alias with lambda syntax: alias fun2=a=fun(a);
On 06/05/14 08:58, Timothee Cour via Digitalmars-d-learn wrote: //none of those work: //alias fun2=a=fun(a); alias fun2=ALIAS!(a=fun(a)); That 'ALIAS' template will need to be in module scope. alias ALIAS(alias A) = A; artur
Re: alias with lambda syntax: alias fun2=a=fun(a);
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.