www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Overloading and templates

reply Falk-Florian Henrich <schreibmalwieder hammerfort.de> writes:
Hi,

the following question concerns future plans regarding overloading rules 
and templates. Currently, there exists the following problem: Suppose I 
have a templated function

Y[] map(X,Y)(Y function(X[]) f, X[] x);

Now, if I have a couple of overloaded print functions

char[] toString(int);
char[] toString(double);

and do 

map(&toString, x);

where x is some double[], the compiler will grab toString(int) instead of 
its double version. Actually, the compiler grabs just *the first function 
it finds* in the source file - although it does know that the types won't 
match.

1. Why does the compiler only compare the function's name with the given 
candidates, and not the types?

2. Are there any plans to overcome this limitation?

Best regards

Falk


P.S.: I tried several template constructions to find a workaround but 
didn't succeed so far.
Mar 27 2007
next sibling parent Falk Henrich <schreibmalwieder hammerfort.de> writes:
Falk-Florian Henrich wrote:

 Y[] map(X,Y)(Y function(X[]) f, X[] x);
but he probably wanted to write Y[] map(X,Y)(Y function(X) f, X[] x); Falk
Mar 27 2007
prev sibling parent reply "Stewart Gordon" <smjg_1998 yahoo.com> writes:
"Falk-Florian Henrich" <schreibmalwieder hammerfort.de> wrote in message 
news:pan.2007.03.27.18.42.25 hammerfort.de...
 Hi,

 the following question concerns future plans regarding overloading rules
 and templates. Currently, there exists the following problem: Suppose I
 have a templated function

 Y[] map(X,Y)(Y function(X[]) f, X[] x);

 Now, if I have a couple of overloaded print functions

 char[] toString(int);
 char[] toString(double);

 and do

 map(&toString, x);

 where x is some double[], the compiler will grab toString(int) instead of
 its double version. Actually, the compiler grabs just *the first function
 it finds* in the source file - although it does know that the types won't
 match.
<snip> This is just one case of something that's been brought up quite a few times: http://d.puremagic.com/issues/show_bug.cgi?id=52 Stewart.
Mar 28 2007
parent Falk-Florian Henrich <schreibmalwieder hammerfort.de> writes:
Am Wed, 28 Mar 2007 15:08:14 +0100 schrieb Stewart Gordon:

 This is just one case of something that's been brought up quite a few
 times:
 
 http://d.puremagic.com/issues/show_bug.cgi?id=52
 
 Stewart.
Sorry, I wasn't aware of that. Falk
Mar 28 2007