Why is there std::lexicographical_compare_three_way
, but no std::ranges::lexicographical_compare_three_way
?
The algorithms in std::ranges
are constrained by concept
s while the algorithms in std
are not. So, for instance, std::ranges::lexicographical_compare
(which uses a two-way comparison, defaulting to <
) is specified as:
template<input_range R1, input_range R2, class Proj1 = identity,
class Proj2 = identity,
indirect_strict_weak_order<projected<iterator_t<R1>, Proj1>,
projected<iterator_t<R2>, Proj2>> Comp = ranges::less>
constexpr bool
lexicographical_compare(R1&& r1, R2&& r2, Comp comp = {},
Proj1 proj1 = {}, Proj2 proj2 = {});
Notably, we have the concept indirect_strict_weak_order
to explain the syntactic and semantic requirements for the comparison operation you need in order for this algorithm to be meaningful.
However, nobody has (yet) done the work to formulate the corresponding concept
s for three-way comparison. Note that strict_weak_order
has very strong semantic requirements, and we would need the equivalent for a hypothetical strict_weak_order_three_way
(or some other name that sucks less).
The interesting thing here is that we need to not reject partial_ordering
, but rather only require that no two elements in the domain compare as partial_ordering::unordered
.
Once we have such concept
s, then specifying and implementing std::ranges::lexicographical_compare_three_way
is pretty straightforward.