"cannot deduce function from argument types" issue.

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Feb 10 01:43:56 PST 2015


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 hints given by the programmer. 
They work "forward" from the rules.

However, both in your example above and in ted's code, the compiler has 
to solve a problem similar to declarative programming languages to 
arrive at the intent. For example, it must apply sqrt to the second 
length to figure out N.

Admittedly, it is not apparent in the code above because the first 
parameter is already trivially N so the human reader thinks "N comes 
from the first argument and it must also satisfy the second argument".

The following would ask the compiler to work backward from the argument:

void bar(size_t N)(int[N ^^ 2] b) {}

"Take a value from the argument, take its square root and then use that 
value to figure out the instantiation value of this template."

Ali



More information about the Digitalmars-d-learn mailing list