struct opCmp?

Christopher Wright dhasenan at gmail.com
Fri May 15 04:06:01 PDT 2009


Frits van Bommel wrote:
> Nick Sabalausky wrote:
>> Can anyone think of a reasonable case where it would actually make 
>> sense to override opCmp, but not opEquals? (that is, without 
>> bastardizing them like in a "C++ streams" kind of way) 
> 
> How about a struct you want to be opCmp()-comparable (which, according 
> to the spec, they aren't by default), but for which equality means 
> bitwise-equality?
> 
> Similarly, a class that's uniqued (so there are no equal instances that 
> aren't actually the same instance, i.e. comparison means 
> pointer-comparison), yet that has some kind of natural ordering 
> implemented through opCmp().

In these cases, you can override opEquals to do the bitwise comparisons 
or pointer comparisons. They're relatively rare, I think.

And that natural ordering has to be a total ordering.


More information about the Digitalmars-d-learn mailing list