Either I'm just too stupid, or D is lacking something

Sean Kelly sean at f4.ca
Tue Jul 25 10:22:43 PDT 2006


Wolfgang Draxinger wrote:
> Sean Kelly wrote:
> 
>> This may make IFTI much more achievable in the short-term, as
>> overloading template functions basically doesn't work at all
>> now.  I think mixing the two might be more complicated for the
>> compiler to sort out:
>>
>> template fn( T )
>> {
>>      void fn( T[] x ) {}
>>      void fn( T x ) {}
>> }
>>
>> template fn( T : int[] )
>> {
>>      void fn( T[] x ) {}
>> }
>>
>> template fn( T : int )
>> {
>>      void fn( T x ) {}
>> }
> 
> Umm, even me, being not a compiler, wouldn't know how to decide
> which of those templates to use. That's a highly ambiguos
> example of code and no sane compiler would process that.

It's perfectly legal.  Since the most specialized overload is chosen, 
the last two functions would be called for int arrays or int parameters, 
and the first two functions would be called for arrays and non-arrays 
otherwise.


Sean



More information about the Digitalmars-d mailing list