Thread overview | |||||
---|---|---|---|---|---|
|
December 10, 2005 General comparsion operator | ||||
---|---|---|---|---|
| ||||
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 |
December 12, 2005 Re: General comparsion operator | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chris Sauls | Could basically be the same as operator !=, no? What if that one returned a different non-zero value for < and > ? L. |
December 12, 2005 Re: General comparsion operator | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chris Sauls | 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 story If the starship operator *is* added, it should look the same. (<=>) It will blend right in with the D floating point comparison ones: !<>= <> <>= !<= !< !>= !> !<> --anders |
Copyright © 1999-2021 by the D Language Foundation