[Issue 1856] Outstanding template issues

Don Clugston dac at nospam.com.au
Mon Mar 10 05:59:40 PDT 2008


d-bugmail at puremagic.com wrote:
> http://d.puremagic.com/issues/show_bug.cgi?id=1856
> 
> 
> 
> 
> 
> ------- Comment #5 from wbaxter at gmail.com  2008-03-10 04:36 -------
> (In reply to comment #4)
>> d-bugmail at puremagic.com wrote:
>>> http://d.puremagic.com/issues/show_bug.cgi?id=1856
>>>> However, there it says "the function is not preferred over the template" so
>>> that means this would be an error?
>>>
>>>   void foo(int i);
>>>   void foo(T)(T i);
>>>
>>> That doesn't seem so good.  Why not treat functions like specializations?
>> I think that's the idea. In C, when there's a function and a template, the 
>> compiler ALWAYS chooses the function. No matter how inappropriate the function
>> is.
> 
> So you're saying 
>  int x = 3;
>   foo(3);
> would call the function instead of the generic template?
> If so then ok.
Yes.

> If it's an ambiguity error, then that's ok too I suppose.
> But if it prefers the template in this case, that seems like it could lead to
> unexpected results.

short x=3;
foo(x)
would call the template, not the function. IIRC C++ would use the function.




More information about the Digitalmars-d-bugs mailing list