Some algorithms in STL, such as sort and binary_search, require that the object have a well-defined strict weak ordering. Strict weak order is a strict partial order, but an additional condition is met, that is, for the two elements X in the set,
Y. The following conditions are met,
That is, if there is no comparability between x and y, then X and Y are equivalent. If the element Z still exists ~ Z or Y ~ Z, then x ~ Y ~ Z, which is passed.
Obviously, for any element X, X is equivalent to X itself (according to the definition of strict weak order ).
In C ++, strict weak order is used to define equivalence instead of =. In this way, we only need to ensure a well-defined <to ensure the correctness of sort.
Sometimes when our object has multiple comparable members (Multiple Primary keys), how should we define them? We know how to compare strings. strings are determined based on character-by-character comparison. For example, for ABC and ABD, we first compare the first two characters and findEqualSo we compared the last character and found C <D, so ABC <Abd, which is the Lexicographic Order ). We can also use a similar idea to compare multiple primary keys.EqualThis concept, in strict weak order, is called equivalence, and is used
<To indicate this equivalent relationship, that is
Therefore, assume that there are two objects, A and B, and there is a primary key.
If we can find a J that satisfies
Q is available to meet
So
.
Refer:
[1] http://en.wikipedia.org/wiki/Weak_ordering
[2] http://en.wikipedia.org/wiki/Equivalence_class
[3] http://www.sgi.com/tech/stl/StrictWeakOrdering.html (note that antisypolicric is used in the definition of strict weak order, which is incorrect and should be non-symmetric, that is, asypolicric ).
[4] http://www.drdobbs.com/author/Andrew-Koenig (several articles about ordering here)