| Thread overview | ||||||
|---|---|---|---|---|---|---|
|
March 27, 2007 Overloading and templates | ||||
|---|---|---|---|---|
| ||||
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. | ||||
March 27, 2007 Re: Overloading and templates | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Falk-Florian Henrich | 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
| |||
March 28, 2007 Re: Overloading and templates | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Falk-Florian Henrich | "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. | |||
March 28, 2007 Re: Overloading and templates | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | 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
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply