Re: Overloading funtion templates.

2017-06-30 Thread Balagopal Komarath via Digitalmars-d-learn
On Friday, 30 June 2017 at 04:51:23 UTC, vit wrote: import std.traits : isCallable; auto foo(alias F, T)(T x) if(isCallable!F)//this line is optional { return F(x); } Thanks. That works.

Re: Overloading funtion templates.

2017-06-29 Thread vit via Digitalmars-d-learn
On Thursday, 29 June 2017 at 06:40:04 UTC, Balagopal Komarath wrote: On Wednesday, 28 June 2017 at 12:19:31 UTC, vit wrote: auto foo(alias F, T)(T x) { return x.foo(); } With this definition foo!((x) => x+1)(3); doesn't work. Is there a way to solve this? You donĀ“t need overload

Re: Overloading funtion templates.

2017-06-28 Thread vit via Digitalmars-d-learn
On Wednesday, 28 June 2017 at 11:49:57 UTC, Balagopal Komarath wrote: Shouldn't the compiler be able to resolve foo!g(3) to the first template foo? import std.stdio; import std.algorithm; import std.range; auto foo(F, T)(T x) { return x.foo(F); } auto foo(F, T)(T x, F f) { return