Search⌘ K

opCmp

Explore the role of opCmp in D for sorting class objects by defining custom comparison logic. Understand how to return appropriate values for less than, equal, or greater comparisons, ensure consistency with opEquals, and handle comparisons involving inheritance and string members.

opCmp for class objects

This operator is used when sorting class objects. opCmp is the function that gets called behind the scenes for the <, <=, >, and >=.

This operator must return a negative value when the left-hand object is before, a positive value when the left-hand object is after, and zero when both objects have the same sorting order.

Warning: The definition of this function ...