May 15, 2009 Re: struct opCmp? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Frits van Bommel | 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.
|
Copyright © 1999-2021 by the D Language Foundation