overloading functions against function templates

BCS none at anon.com
Fri Jul 31 07:44:20 PDT 2009


Hello Lars,

> If you are going to allow ordinary and templated functions to overload
> against each other, there is a problem with IFTI that I think will
> become more visible. It's something I run into all the time:
> 
> T sum(T)(T a, T b) { return a + b; }
> 
> real x = 2.0;
> 
> real y = sum(1.0, x);
> 
> The above doesn't compile, because 1.0 is a double literal, while x is
> a real. However, if this was an ordinary function with T->real, it
> would be valid code. I think it should also work with templates.

Ditto on this 

> 
> Granted, I don't know how the matching procedure works now, but for
> this case I picture it could be something like this:
> 
> Given:
> 
> T sum(T)(T a, T b, T c) { return a + b + c; }
> 
> sum(x, y, z);
> 
> then do the following:
> 1: Try T = typeof(x). If it works, use it.
> 2: Try T = typeof(y). If it works, use it.
> 3: Try T = typeof(z). If it works, use it.
> 4: Give template matching error.

Something about that rules set doesn't seem rigorous enough. I'm not sure 
what.





More information about the Digitalmars-d mailing list