9#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ALGORITHM_LEXICOGRAPHICAL_COMPARE_HPP_
10#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ALGORITHM_LEXICOGRAPHICAL_COMPARE_HPP_
21#include "arene/base/stdlib_choice/less.hpp"
28namespace lexicographical_compare_detail {
32class lexicographical_compare_fn {
45 template <
typename Itr1,
typename Itr2,
typename BinaryPredicate = std::less<>>
47 operator()(Itr1 first_itr, Itr1 first_end, Itr2 second_itr, Itr2 second_end, BinaryPredicate cmp = {})
const noexcept
53 "cmp must be invocable with the elements from the input sequences and return a boolean-convertible value"
57 "cmp must be invocable with the elements from the input sequences and return a boolean-convertible value"
60 bool first_at_end{first_itr == first_end};
61 bool second_at_end{second_itr == second_end};
62 while ((!first_at_end) && (!second_at_end)) {
63 if (cmp(*first_itr, *second_itr)) {
66 if (cmp(*second_itr, *first_itr)) {
69 arene::base::advance(first_itr, 1);
70 arene::base::advance(second_itr, 1);
71 first_at_end = first_itr == first_end;
72 second_at_end = second_itr == second_end;
74 return first_at_end && (!second_at_end);
80class lexicographical_compare_three_way_fn {
95 template <
typename Itr1,
typename Itr2,
typename Comparator = compare_three_way>
97 operator()(Itr1 first_itr, Itr1 first_end, Itr2 second_itr, Itr2 second_end, Comparator tw_comp = {})
const noexcept
103 "tw_comp must be invocable with the value_type of the intput iterators and return a strong_ordering"
106 bool first_at_end{first_itr == first_end};
107 bool second_at_end{second_itr == second_end};
108 while ((!first_at_end) && (!second_at_end)) {
109 auto const comp_r = tw_comp(*first_itr, *second_itr);
110 if (comp_r != strong_ordering::equal) {
113 arene::base::advance(first_itr, 1);
114 arene::base::advance(second_itr, 1);
115 first_at_end = first_itr == first_end;
116 second_at_end = second_itr == second_end;
118 if (first_at_end && (!second_at_end)) {
119 return strong_ordering::less;
121 return first_at_end && second_at_end ? strong_ordering::equal : strong_ordering::greater;
142 lexicographical_compare_detail::lexicographical_compare_three_way_fn,
143 lexicographical_compare_three_way
Provides a backport of C++17's constexpr std::advance.
#define ARENE_CPP14_INLINE_VARIABLE(type, name)
Emulates C++17's inline variable declarations for function objects.
Definition cpp14_inline.hpp:69
Definition accumulate.hpp:37
strong_ordering_detail::strong_ordering strong_ordering
The enumeration specifying the result of an ordering comparison.
Definition strong_ordering.hpp:147
constexpr bool is_invocable_r_v
Determine if a functor type is invocable with the specified return and argument types.
Definition accumulate.hpp:36
bool
Check if element Idx and all subsequent elements of the two tuples are equal.
Definition tuple.hpp:649
#define ARENE_NODISCARD
An alias for [[nodiscard]] , or a no-op if the attribute is not supported.
Definition nodiscard.hpp:26