www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - overloading between templates and non-templates

reply #ponce <cont4ct gamesfr0mmar5.fr> writes:
In D2 :


1/ Is it valid to have two functions with the same name, one templated and
another not ? I remember a NG thread but cannot find it.

void A(int x) { // blah }
void A(T)(T x) { // blah }

2/ If (1)'s answer is yes, is it equivalent to a template specialization?

void A(int x) { // blah }
void A(T)(T x) { // blah }

A(x); // first function called

3/ If (2)'s answer is no, how is overloading resolved with :

void A(int x) { // blah }
void A(T)(T x) if (is(T== int)) { // blah }

A(x); // which function called ?

Many thanks.
Dec 14 2010
parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Tue, 14 Dec 2010 13:17:11 -0500, #ponce <cont4ct gamesfr0mmar5.fr>  
wrote:

 In D2 :


 1/ Is it valid to have two functions with the same name, one templated  
 and another not ? I remember a NG thread but cannot find it.

Yes, but it's not properly implemented. The ability is specified in TDPL. There is a bug somewhere I think.
 2/ If (1)'s answer is yes, is it equivalent to a template specialization?

I would have to guess yes (the opposite makes no sense), but I'm unsure of the full semantics (don't have a copy of TDPL). What's unclear to me is if the argument implicitly converts what is chosen. -Steve
Dec 14 2010