Function templates do implicit conversions for their arguments

TommiT tommitissari at hotmail.com
Fri Jul 5 00:28:24 PDT 2013


On Friday, 5 July 2013 at 02:45:47 UTC, Maxim Fomin wrote:
> On Thursday, 4 July 2013 at 21:31:43 UTC, TommiT wrote:
>> On Thursday, 4 July 2013 at 20:43:45 UTC, Maxim Fomin wrote:
>>>
>>> Implementation may do other way, at first instantiate 
>>> template (with deduced type) and then try to plug arguments 
>>> as in case of non-template function (including implicit 
>>> conversion). If it cannot, implementation issues error 
>>> message for a particular problem and then general "template 
>>> error instantiation".
>>
>> Well, it doesn't really matter how it is implemented. What 
>> matters is that the implicit conversion does happen.
>
> Issue in this case is not that it happens per se (of course, it 
> does), but whether implicit conversion influences type 
> deduction. As it was mentioned previously about particular 
> example, it does not.

Of course implicit conversion influences type deduction. If it 
didn't, if implicit conversion didn't have any say in type 
deduction, then the call foo(sa) would not compile. The compiler 
needs to know, and thus has to be influenced by the knowledge of 
implicit conversion, in order to be able to deduce T to be int.


On Friday, 5 July 2013 at 02:45:47 UTC, Maxim Fomin wrote:
>>
>>> What are your points regarding type deduction and implicit 
>>> conversion in D?
>>
>> I thought my point would have been made painstakingly clear by 
>> now. My point is that D behaves in a way that's very different 
>> from C++ or any other language which does heterogeneous 
>> translation of type parameters. And I've never seen any 
>> mention of this neither in the spec nor in TDPL (nor have I 
>> seen this discussed before). This difference should be 
>> mentioned somewhere newcomers are guaranteed to see it.
>
> Please provide evidence which support your point about D. 
> Previous example doesn't do that. Piece of dmd implementation 
> is appreciated. Otherwise claims about what implementation does 
> are of little value.

The evidence of that D behaves differently from C++ is that 
foo(sa) compiles. I only talked about a possible implementation 
of it in DMD in order to explain this thing to you. But the 
actual implementation of it in DMD doesn't matter.


More information about the Digitalmars-d mailing list