It doesn't require <
as such, it requires a strict weak ordering.
In short, if the function before
is the ordering relation, then the following must hold:
- For all
x
, before(x, x)
is false
- For all
x
and y
, if before(x, y)
is true then before(y, x)
is false
- For all
x
, y
, and z
, if before(x, y)
is true and before(y, z)
is true, then before(x, z)
is true
The <
relation is the default because it is already defined for many types, in a way that fulfills the strict weak ordering conditions.
(Exercise: verify that it does.)
The ordering relation is used to establish an equivalence relation between elements; if a
is not ordered before b
, and b
is not ordered before a
- that is, !before(a,b) && !before(b, a)
- then they are considered equivalent.
Equivalent elements belong to the same "multi-element" of the multiset (note that, unlike with std::set
, equivalent elements can occur more than once).
The multiset itself is ordered according to the ordering relation.
Even if you can't define a "strictly less than" relation for a type, you can usually define a "should be ordered 'before' for this particular purpose" relation.