digitalmars.D - Converting a C MACRO in D
- Pac (10/10) Jul 15 2004 Hi,
- Vathix (11/21) Jul 15 2004 (http://www.digitalmars.com//d/htomodule.html)
- Norbert Nemec (3/36) Jul 15 2004 ... once again crying out for implicit instantiation of function
- Matthew Wilson (4/40) Jul 16 2004 Hey, you should see the mess I'm in with DTL without impl ex.! Nonethele...
-
Andy Friesen
(3/18)
Jul 16 2004
And how:
Hi, it is written on the D web site (http://www.digitalmars.com//d/htomodule.html) that macros like #define MAX(a,b) ((a) < (b) ? (b) : (a)) should be remplaced by : int MAX(int a, int b) { return (a < b) ? b : a); } But what if we want real, float or double type for the arguments ? iS it possible to overload the function ? Best regards Pac
Jul 15 2004
"Pac" <Pac_member pathlink.com> wrote in message news:cd6hmp$2am7$1 digitaldaemon.com...Hi, it is written on the D web site(http://www.digitalmars.com//d/htomodule.html)that macros like #define MAX(a,b) ((a) < (b) ? (b) : (a)) should be remplaced by : int MAX(int a, int b) { return (a < b) ? b : a); } But what if we want real, float or double type for the arguments ? iS it possible to overload the function ? Best regards PacYes, you can overload functions. But in this case, a template might be better: template MAX(T) { T MAX(T a, T b) { return (a < b) ? b : a); } } int foo = MAX!(int)(1, 2); float bar = MAX!(float)(1.0, 2.0);
Jul 15 2004
Vathix wrote:"Pac" <Pac_member pathlink.com> wrote in message news:cd6hmp$2am7$1 digitaldaemon.com...... once again crying out for implicit instantiation of function templates. :-)Hi, it is written on the D web site(http://www.digitalmars.com//d/htomodule.html)that macros like #define MAX(a,b) ((a) < (b) ? (b) : (a)) should be remplaced by : int MAX(int a, int b) { return (a < b) ? b : a); } But what if we want real, float or double type for the arguments ? iS it possible to overload the function ? Best regards PacYes, you can overload functions. But in this case, a template might be better: template MAX(T) { T MAX(T a, T b) { return (a < b) ? b : a); } } int foo = MAX!(int)(1, 2); float bar = MAX!(float)(1.0, 2.0);
Jul 15 2004
"Norbert Nemec" <Norbert.Nemec gmx.de> wrote in message news:cd7toq$2spk$1 digitaldaemon.com...Vathix wrote:Hey, you should see the mess I'm in with DTL without impl ex.! Nonetheless, the fog's are slowly clearing ... :)"Pac" <Pac_member pathlink.com> wrote in message news:cd6hmp$2am7$1 digitaldaemon.com...... once again crying out for implicit instantiation of function templates. :-)Hi, it is written on the D web site(http://www.digitalmars.com//d/htomodule.html)that macros like #define MAX(a,b) ((a) < (b) ? (b) : (a)) should be remplaced by : int MAX(int a, int b) { return (a < b) ? b : a); } But what if we want real, float or double type for the arguments ? iS it possible to overload the function ? Best regards PacYes, you can overload functions. But in this case, a template might be better: template MAX(T) { T MAX(T a, T b) { return (a < b) ? b : a); } } int foo = MAX!(int)(1, 2); float bar = MAX!(float)(1.0, 2.0);
Jul 16 2004
Norbert Nemec wrote:And how: <http://andy.tadan.us/d/tuple.d> -- andyYes, you can overload functions. But in this case, a template might be better: template MAX(T) { T MAX(T a, T b) { return (a < b) ? b : a); } } int foo = MAX!(int)(1, 2); float bar = MAX!(float)(1.0, 2.0);... once again crying out for implicit instantiation of function templates. :-)
Jul 16 2004