Ordering comparisons

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Mon Mar 6 18:51:37 PST 2017


On Monday, March 06, 2017 20:27:56 Andrei Alexandrescu via Digitalmars-d 
wrote:
> While reviewing work on array comparisons, Vladimir found an odd issue:
>
> https://issues.dlang.org/show_bug.cgi?id=17244
>
> Investigation reveals that during array comparison for inequality,
> structs are compared by means of memcmp - even if they don't define
> opCmp, and regardless of the types of their fields. This has obvious
> unpleasant consequences:

> The question is what to do to minimize breakage yet "break the bad
> code". The most backward-compatible solution is to define opCmp
> automatically to do a field-by-field lexicographical comparison. The
> most radical solution is disable ordering comparisons unless explicitly
> implemented by the user.

If we can, we should probably make structs that have opCmp use opCmp like
they should, and those that don't continue to use memcmp for the moment but
get a deprecation message. Then after whatever amount of time we think is
appropriate, we disable the comparisons. So, we don't break anything
immediately, but ultimately end up with the correct situation of comparisons
not working unless opCmp being defined. That being said, depending on how
all of that is implemented, I don't know how easy that approach is.

- Jonathan M Davis



More information about the Digitalmars-d mailing list