opCmp, [partial/total/pre]orders, custom floating point types etc.
John Colvin via Digitalmars-d
digitalmars-d at puremagic.com
Tue Jan 12 12:01:29 PST 2016
On Tuesday, 12 January 2016 at 19:28:36 UTC, Andrei Alexandrescu
wrote:
> On 01/12/2016 02:13 PM, John Colvin wrote:
>> a<=b and b<=a must also be false.
>
> Would the advice "Only use < and == for partially-ordered data"
> work? -- Andrei
If by that you mean "Only use <= or >= on data that defines a
total ordering"* I guess it would work, but it has some pretty
big downsides:
1) Annoying to use.
2) You have to use the opCmp return 0 (which normally means
a[<>]=b && b[<>]=a) to mean "not comparable".
3) Not enforceable. Because of 2 you'll always get true if you
use >= or <= on any a pair that doesn't have a defined ordering.
4) inefficient (have to do both < and == separately which can be
a lot more work than <=).
*would be safer to say "types that define", but strictly
speaking...
More information about the Digitalmars-d
mailing list