Suggestion: function template overloading

Walter Bright newshound at digitalmars.com
Tue Aug 29 12:09:32 PDT 2006


Sean Kelly wrote:
> Kristian wrote:
>>
>> It would be very nice if you could overload function templates as you 
>> can in C++. Here is what I mean:
>>
>> void f(T)(T val) {...}
>>
>> void f(int val) {...}  //error: conflicts with the template function
>>
>> It would allow you to write special cases for types that need it.
> 
> void f(T)(T val) {}
> void f()(int val) {}

Or:
	void f(T:int)(T val) {}

The trouble is that D has problems with specialization, but that's a 
compiler problem.

C++ has complex rules regarding mixing functions and function templates 
with the same name. D just sidesteps the problem by disallowing that. 
There's no loss of functionality.

I think the reason C++ did that was because the template design 
originally didn't allow template specialization, and when it did, it was 
stuck with the legacy code.



More information about the Digitalmars-d mailing list