ProtoObject and comparison for equality and ordering

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed May 15 00:12:27 UTC 2019


On 5/14/19 12:13 AM, H. S. Teoh wrote:
> Moreover, Andrei has mentioned before that opCmp can technically be used
> for implementing partial orders. I had thought otherwise in the past,
> because I only considered opCmp that returns int. However, if opCmp is
> allowed to return float, then you can return float.nan for the
> incomparable case (e.g., two sets that are not subsets of each other)
> and thus achieve a non-linear partial ordering, such as the subset
> relation.
> 
> Whether or not this is a*good*  way of implementing the subset operation
> is a different question, of course. If we restricted opCmp to only
> linear orderings, then this wouldn't be an issue.

opCmp returning float has become a popular D idiom, and banking on that 
is the right thing to do.


More information about the Digitalmars-d mailing list