Comparison: when operator<() is better than opCmp()

OF nospam at nospammington.com
Sat Sep 8 05:13:59 PDT 2007


Giuseppe Bilotta Wrote:

> Hello all,
> [...]
> 
> How does the idea sound?
> 
> -- 
> Giuseppe "Oblomov" Bilotta

It's sound like it's not worth it. It might be, but you need a better example to show it. The use of operator overloading in your example isn't very solid.

There's no naturally defined order. This easily makes operator overloading of compare operators more confusing than helpful. You need to read the documents or code to fully understand a <= b, and that !(a > b) doesn't equal a <= b even with correct input.

I'd recommend functions like aboveRange, inRange and belowRange or something similar for this.



More information about the Digitalmars-d mailing list