Function templates do implicit conversions for their arguments

TommiT tommitissari at hotmail.com
Wed Jul 3 13:33:24 PDT 2013


Apparently I'm correct with my initial assertion after all, but 
only as it relates to implicit conversion from static to dynamic 
arrays. Let me start this thread again by using my initial 
opening statement:

This is a pretty big delta between C++ and D. It's going to 
surprise everybody coming from C++, especially when it says in 
TDPL (page 140) that: "However, having the language attempt
combinatorially at the same time implicit conversions and type 
deduction is a dicey proposition in the general case, so D does 
not attempt to do all that".

Now, here's a new example:

void foo(T)(T[] slice) { }

void main()
{
     int[10] arr;
     foo(arr);
}

See what I mean? int[10] is a distinct type from int[], so an 
implicit conversion must happen before 'arr' is passed to 'foo'. 
Implicit conversions never happen for arguments passed to 
templated functions in C++ (and neither in D according to that 
quote from TDPL above).

And I'll just finish with my initial closing argument:
This difference between D and C++ should be noted somewhere in 
the documentation with big red letters.


More information about the Digitalmars-d mailing list