digitalmars.D - General comparsion operator
- Chris Sauls (11/11) Dec 10 2005 The Ruby language defines a comparison operator "<=>" whose value is a n...
- Lionello Lunesu (3/3) Dec 12 2005 Could basically be the same as operator !=, no? What if that one returne...
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (8/18) Dec 12 2005 +1
The Ruby language defines a comparison operator "<=>" whose value is a negative if the left-hand operand is "less than" the right-hand operand, positive if the reverse, or zero if they are equivelant. Fairly straightforward, yes. Would an equivelant operator be useful in D? The matter of overloading is taken care of, as it would just directly use the value of .opCmp() since it already follows this convention. What would such an operator look like in D, I wonder? cmp = a <=> b ; cmp = a <-> b ; cmp = a b ; cmp = a >< b ; // I'd rather reserve this one as a swap operator, but that's another story -- Chris Sauls
Dec 10 2005
Could basically be the same as operator !=, no? What if that one returned a different non-zero value for < and > ? L.
Dec 12 2005
Chris Sauls wrote:The Ruby language defines a comparison operator "<=>" whose value is a negative if the left-hand operand is "less than" the right-hand operand, positive if the reverse, or zero if they are equivelant. Fairly straightforward, yes. Would an equivelant operator be useful in D?+1 I also like the old "starship operator", as Perl fondly calls it. Very useful for writing simpler sorting functions, for instance ?What would such an operator look like in D, I wonder? cmp = a <=> b ; cmp = a <-> b ; cmp = a b ; cmp = a >< b ; // I'd rather reserve this one as a swap operator, but that's another storyIf the starship operator *is* added, it should look the same. (<=>) It will blend right in with the D floating point comparison ones: !<>= <> <>= !<= !< !>= !> !<> --anders
Dec 12 2005