cannot deduce function from argument types issue.

2015-02-10 Thread ted via Digitalmars-d-learn
Hi! I get the following compile error (linux, dmd2.066.1): test.d(13): Error: template test.testFunc cannot deduce function from argument types !()(double[], double), candidates are: test.d(3):test.testFunc(R)(R range, ElementType!R foo) For the following test file: import std.range:

Re: cannot deduce function from argument types issue.

2015-02-10 Thread ted via Digitalmars-d-learn
Ali Çehreli wrote: On 02/10/2015 12:31 AM, ted wrote: ElementType!R testFunc(R)( R range, ElementType!R foo) // compiles with double foo If think it is a little too much to ask from the template system of D. A proper way of doing the same thing is to use a template constraint:

Re: cannot deduce function from argument types issue.

2015-02-10 Thread Ali Çehreli via Digitalmars-d-learn
On 02/10/2015 12:31 AM, ted wrote: ElementType!R testFunc(R)( R range, ElementType!R foo) // compiles with double foo If think it is a little too much to ask from the template system of D. A proper way of doing the same thing is to use a template constraint: ElementType!R testFunc(R,

Re: cannot deduce function from argument types issue.

2015-02-10 Thread bearophile via Digitalmars-d-learn
ted: Could someone enlighten me ? This works: import std.range: ElementType, isInputRange; ElementType!R testFunc(R, T)(R range, T foo) if (is(ElementType!R == T)) { static assert(isInputRange!R); typeof(return) retVal = foo ^^ 2; // More DRY. return retVal; } void main() {

Re: cannot deduce function from argument types issue.

2015-02-10 Thread bearophile via Digitalmars-d-learn
Ali Çehreli: If think it is a little too much to ask from the template system of D. I remember hitting a similar problem with code like this bar() function: // OK void foo(size_t N1, size_t N2)(int[N1] a, int[N2] b) if (N2 == N1 ^^ 2) {} // Not OK void bar(size_t N)(int[N] a, int[N ^ 2]

Re: cannot deduce function from argument types issue.

2015-02-10 Thread bearophile via Digitalmars-d-learn
void bar(size_t N)(int[N] a, int[N ^ 2] b) {} I meant: void bar(size_t N)(int[N] a, int[N ^^ 2] b) {}

Re: cannot deduce function from argument types issue.

2015-02-10 Thread ted via Digitalmars-d-learn
bearophile wrote: ted: Could someone enlighten me ? This works: import std.range: ElementType, isInputRange; ElementType!R testFunc(R, T)(R range, T foo) if (is(ElementType!R == T)) { static assert(isInputRange!R); typeof(return) retVal = foo ^^ 2; // More DRY.

Re: cannot deduce function from argument types issue.

2015-02-10 Thread ted via Digitalmars-d-learn
bearophile wrote: ted: ... where you say 'More DRY' above, are you referring to I was referring to both, but mostly to the typeof. It's more DRY (http://en.wikipedia.org/wiki/Don%27t_repeat_yourself ). You are stating only once the type of the return variable. This is less bug-prone.

Re: cannot deduce function from argument types issue.

2015-02-10 Thread bearophile via Digitalmars-d-learn
ted: ... where you say 'More DRY' above, are you referring to I was referring to both, but mostly to the typeof. It's more DRY (http://en.wikipedia.org/wiki/Don%27t_repeat_yourself ). You are stating only once the type of the return variable. This is less bug-prone. Bye, bearophile

Re: cannot deduce function from argument types issue.

2015-02-10 Thread Ali Çehreli via Digitalmars-d-learn
On 02/10/2015 01:08 AM, bearophile wrote: // Not OK void bar(size_t N)(int[N] a, int[N ^^ 2] b) {} So perhaps my suggestion to file an enhancement request is not a good idea... I am not sure. Although the template system already does pretty clever deductions, I think they are all based on