digitalmars.D - Min/max operators in D
- Marti (11/11) Oct 28 2004 I think having min/max operators built into the language would be useful...
- Sean Kelly (6/7) Oct 28 2004 It's a pretty cool idea, especially in the absence of macros. A standar...
- Thomas Kuehne (8/15) Oct 28 2004 This would be an extreamly usefull extentsion.
- Ant (8/26) Oct 28 2004 what's your problem? can't you do:
-
Markus Dangl
(3/9)
Dec 28 2004
- Stewart Gordon (4/12) Oct 29 2004 And what would be the return type of such a function?
- Sean Kelly (10/25) Oct 29 2004 Oops, good point. There are two-type versions in C++, but they
I think having min/max operators built into the language would be useful. A good example might be the GCC C++ min/max extension [1]: a <? b is the minimum, returning the smaller of the numeric values a and b; a >? b is the maximum, returning the larger of the numeric values a and b. These operators can also be chained, eg. `1 >? 2 >? 3`, to compare more than two variables. Even though its implementation should take minimal resources and effort, I'm not sure if would pay off in terms of language/compiler complexity. [1] http://gcc.gnu.org/onlinedocs/gcc-3.4.2/gcc/Min-and-Max.html
Oct 28 2004
In article <clr0ja$2elt$1 digitaldaemon.com>, Marti says...I think having min/max operators built into the language would be useful.It's a pretty cool idea, especially in the absence of macros. A standard template implementation would have to be called as: std.min!(int,float)(x,y); Which seems kind of verbose and a tad brittle. Sean
Oct 28 2004
In article <clr37c$2het$1 digitaldaemon.com>, Sean Kelly says...In article <clr0ja$2elt$1 digitaldaemon.com>, Marti says...This would be an extreamly usefull extentsion. While we are extending, how about a typesafe "swap" opperator for the current code: ThomasI think having min/max operators built into the language would be useful.It's a pretty cool idea, especially in the absence of macros. A standard template implementation would have to be called as: std.min!(int,float)(x,y); Which seems kind of verbose and a tad brittle.
Oct 28 2004
In article <clr54d$2jm6$1 digitaldaemon.com>, Thomas Kuehne says...In article <clr37c$2het$1 digitaldaemon.com>, Sean Kelly says...what's your problem? can't you do: a = b + ((b=a)-a); (it's a joke!, it's a joke! must resist posting..., must resist posting..., oops, to late ;) Ant PS this should work as consistently as i = i++; BTW is i = i++; defined in D?In article <clr0ja$2elt$1 digitaldaemon.com>, Marti says...This would be an extreamly usefull extentsion. While we are extending, how about a typesafe "swap" opperator for the current code:I think having min/max operators built into the language would be useful.It's a pretty cool idea, especially in the absence of macros. A standard template implementation would have to be called as: std.min!(int,float)(x,y); Which seems kind of verbose and a tad brittle.
Oct 28 2004
what's your problem? can't you do: a = b + ((b=a)-a); (it's a joke!, it's a joke! must resist posting..., must resist posting..., oops, to late ;)<joke> a=b-a;b-=a;a+=b; ??? </joke>
Dec 28 2004
Sean Kelly wrote:In article <clr0ja$2elt$1 digitaldaemon.com>, Marti says...And what would be the return type of such a function? I'd think a one-parameter template would suffice.... Stewart.I think having min/max operators built into the language would be useful.It's a pretty cool idea, especially in the absence of macros. A standard template implementation would have to be called as: std.min!(int,float)(x,y);
Oct 29 2004
Stewart Gordon wrote:Sean Kelly wrote:Oops, good point. There are two-type versions in C++, but they typically rely on implicit template instantiation and tend to be quite complicated.In article <clr0ja$2elt$1 digitaldaemon.com>, Marti says...And what would be the return type of such a function?I think having min/max operators built into the language would be useful.It's a pretty cool idea, especially in the absence of macros. A standard template implementation would have to be called as: std.min!(int,float)(x,y);I'd think a one-parameter template would suffice....It would, though still not as well as a macro. But perhaps it isn't as much of an issue as in C++ since D doesn't have implicit template instantiation. I can think of times in C++ code where the result type I'd want to choose would not be very clear, but I can't see this happening in D since all types must be specified by the programmer. Sean
Oct 29 2004