digitalmars.D - Overloading and templates
- Falk-Florian Henrich (21/21) Mar 27 2007 Hi,
- Falk Henrich (4/5) Mar 27 2007 but he probably wanted to write
-
Stewart Gordon
(6/20)
Mar 28 2007
- Falk-Florian Henrich (3/9) Mar 28 2007 Sorry, I wasn't aware of that.
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
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
"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
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