digitalmars.D - Value Range Propagation with generic and specialized function
- Wagner Macedo (28/28) May 22 2014 Hello,
- Etienne (5/8) May 22 2014 Non-template functions are preferred over template, they have priority
- bearophile (4/7) May 22 2014 Perhaps Rust doesn't have function overloading?
- Wagner Macedo (2/6) May 22 2014 Understood. Then, it's expected. Thank you!
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 22 2014
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 22 2014
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 22 2014
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-functionUnderstood. Then, it's expected. Thank you!
May 22 2014









"bearophile" <bearophileHUGS lycos.com> 