Why Templates?

Walter Bright newshound at digitalmars.com
Sat Mar 4 16:50:58 PST 2006


"Sean Kelly" <sean at f4.ca> wrote in message 
news:duda9o$137k$1 at digitaldaemon.com...
> is a bit annoying and reduces readability.  ITI is also quite useful in 
> C++ with respect to how overload resolution is handled, but I have no idea 
> how this will translate to the far simpler overloading rules in D. I think 
> we really may have to simply want and see what Walter comes up with for 
> ITI in D, as simply eliminating the need to explicitly specify template 
> parameters doesn't encompass the full utility of ITI in C++. Will we be 
> able to overload template functions with each other?

Yes.

> Will they also overload with non-template functions?

No. This is a misfeature in C++, and the equivalent can be done with 
explicitly specialized template functions.

> What happens if there are multiple matches?
>
>     class C(T) {}
>
>     template func(T) { void func( T val ) {} }
>     template func(T) { void func( C!(T) val ) {} }
>     void func( C!(int) val ) {}
>
>     func( new C!(int) );
>
> In C++, this is legal and the result is clearly defined (the "most 
> specialized" overload is called), but how will this translate to D?

It'll be the most specialized.

> Will it even be legal?
>
>
> Sean 





More information about the Digitalmars-d mailing list