a quirk in function overloading

Hasan Aljudy hasan.aljudy at gmail.com
Sun Dec 17 21:40:39 PST 2006


I've recently ran across a not-so-convenient behavior of overloading of 
functions, or rather, of function templates.
Before I go into details, I'd like to say that I know this behavior 
complies to the specs .. so please don't reply by saying "this is the 
intended behaviour!!!", I already know that.

So, what am I talking about?

suppose you have a function

void func( int x ) { ... }

and, say you wanted to overload it with

void func( char[] x ) { ... }

So far so good.
but, if you try to overload it with a templated function:

void func(T)() { ... }

woops!! template "func" conflicts with "func"!!

Problem: If you want to overload a function to take a "Type" as a 
parameter, you can't, because func(T)() is not a function, but a 
template with a function inside it, and, the template symbol name 
conflicts with the other "func" functions.

Yes, this is compliant to the specs, I know that, but I see this as a 
problem, because:
The traditional definition of function overloading is tied very much to 
the C language, where there are no templates.

D has templates, and much more, it has function templates.
Shouldn't function overloading be *re-designed* to account for this fact?

While it's true that function templates are not really functions, but 
rather, templates with functions inside them; while that's true, isn't 
it also true that when one writes a function templates, he actually 
thinks about it as a function? Otherwise, why was the
func( T params )( params ){ .. }
syntax introduced?

Please consider this concern.

I myself don't have much of an idea of how this problem could be 
resolved, so I'm just asking for this concert to be considered.

-Hasan



More information about the Digitalmars-d mailing list