PartialOrdering, StrictWeakOrdering, TotalOrdering, what's the main difference in application

后端 未结 1 891
刺人心
刺人心 2021-01-01 00:09

[SGI official document]

Because of irreflexivity and transitivity, operator< always satisfies the definition of a partial ordering. The definiti

1条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-01 01:14

    Partial ordering is, essentially, <=. If both a <= b and b <= a then you may say that a is equivalent to b. But it's also possible that neither a <= b nor b <= a - the two elements are incomparable. As a result, you cannot impose a total order (like std::sort would need to) on a set with partial ordering relation - at best you can do a topological sort. Nor can you derive an equivalence relation - again, there may be elements that are incomparable.

    Strict weak ordering is like <. It doesn't allow having both a < b and b < a, and if neither a < b nor b < a, you can just pronounce a and b equivalent.

    Total ordering is simply strict weak ordering where two elements are equivalent if and only if they are equal (which is only meaningful if you have an equality comparison predicate in addition to less-than predicate, and there is no C++ standard library algorithm that uses both at the same time, so the issue is largely moot in this context).

    0 讨论(0)
提交回复
热议问题