9#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ALGORITHM_LEXICOGRAPHICAL_COMPARE_HPP_
10#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ALGORITHM_LEXICOGRAPHICAL_COMPARE_HPP_
16#include "arene/base/compare/compare_three_way.hpp"
17#include "arene/base/compare/strong_ordering.hpp"
18#include "arene/base/compiler_support/attributes.hpp"
19#include "arene/base/compiler_support/cpp14_inline.hpp"
20#include "arene/base/iterator/advance.hpp"
21#include "arene/base/stdlib_choice/less.hpp"
22#include "arene/base/type_traits/is_invocable.hpp"
28namespace lexicographical_compare_detail {
32class lexicographical_compare_fn {
45 template <
typename Itr1,
typename Itr2,
typename BinaryPredicate = std::less<>>
46 ARENE_NODISCARD
constexpr auto
47 operator()(Itr1 first_itr, Itr1 first_end, Itr2 second_itr, Itr2 second_end, BinaryPredicate cmp = {})
const noexcept
52 is_invocable_r_v<
bool, BinaryPredicate,
decltype(*first_itr),
decltype(*second_itr)>,
53 "cmp must be invocable with the elements from the input sequences and return a boolean-convertible value"
56 is_invocable_r_v<
bool, BinaryPredicate,
decltype(*second_itr),
decltype(*first_itr)>,
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>
96 ARENE_NODISCARD
constexpr auto
97 operator()(Itr1 first_itr, Itr1 first_end, Itr2 second_itr, Itr2 second_end, Comparator tw_comp = {})
const noexcept
102 is_invocable_r_v<strong_ordering, Comparator,
decltype(*first_itr),
decltype(*second_itr)>,
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;
133ARENE_CPP14_INLINE_VARIABLE(lexicographical_compare_detail::lexicographical_compare_fn, lexicographical_compare);
143ARENE_CPP14_INLINE_VARIABLE(
144 lexicographical_compare_detail::lexicographical_compare_three_way_fn,
145 lexicographical_compare_three_way
Definition array_exceptions_disabled.cpp:11
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10