Thread overview | ||||||
---|---|---|---|---|---|---|
|
May 22, 2014 Value Range Propagation with generic and specialized function | ||||
---|---|---|---|---|
| ||||
Hello, Firstly, I'm not an actual D programmer. I'm doing a college research about D language. My point here is that I faced the following situation. With the code above void main() { fun(1f); fun(1); fun(1L); fun!(long)(1L); } void fun(T)(T i) { writeln(typeid(T)); } void fun(int i) { writeln("special => int"); } I get the output float special => int special => int long that is, even if I call fun(1L), with long literal, the VRP decide to use specialized fun(int). Due this, it's needed to specify that I need to use the generic function (losing readability). Said this, I wanted to know if this is a bug or an expected behavior. |
May 23, 2014 Re: Value Range Propagation with generic and specialized function | ||||
---|---|---|---|---|
| ||||
Posted in reply to Wagner Macedo | On 2014-05-22 7:37 PM, Wagner Macedo wrote: > > fun(1); > fun(1L); > fun!(long)(1L); Non-template functions are preferred over template, they have priority even when it's done with implicit conversion. This is the case for C++ as well. http://stackoverflow.com/questions/10291405/priority-between-normal-function-and-template-function |
May 23, 2014 Re: Value Range Propagation with generic and specialized function | ||||
---|---|---|---|---|
| ||||
Posted in reply to Etienne | Etienne:
> Non-template functions are preferred over template, they have priority even when it's done with implicit conversion.
>
> This is the case for C++ as well.
Perhaps Rust doesn't have function overloading?
Bye,
bearophile
|
May 23, 2014 Re: Value Range Propagation with generic and specialized function | ||||
---|---|---|---|---|
| ||||
Posted in reply to Etienne | On Friday, 23 May 2014 at 00:04:00 UTC, Etienne wrote:
> Non-template functions are preferred over template, they have priority even when it's done with implicit conversion.
>
> This is the case for C++ as well.
>
> http://stackoverflow.com/questions/10291405/priority-between-normal-function-and-template-function
Understood. Then, it's expected. Thank you!
|
Copyright © 1999-2021 by the D Language Foundation