16 #ifndef OPENKALMAN_COLLECTION_LEXICOGRAPHICAL_COMPARE_THREE_WAY_HPP 17 #define OPENKALMAN_COLLECTION_LEXICOGRAPHICAL_COMPARE_THREE_WAY_HPP 19 #include <type_traits> 30 template<std::
size_t i = 0,
typename Lhs,
typename Rhs>
31 constexpr stdex::partial_ordering
32 fixed_lexicographical_compare(
const Lhs& lhs,
const Rhs& rhs)
34 using ix = std::integral_constant<std::size_t, i>;
35 constexpr
bool exhaust_lhs = values::size_compares_with<size_of<Lhs>, ix>;
36 constexpr
bool exhaust_rhs = values::size_compares_with<size_of<Rhs>, ix>;
37 constexpr
bool dyn_lhs = values::fixed_value_compares_with<size_of<Lhs>, stdex::dynamic_extent>;
38 constexpr
bool dyn_rhs = values::fixed_value_compares_with<size_of<Rhs>, stdex::dynamic_extent>;
40 if constexpr (exhaust_lhs and exhaust_rhs)
42 return stdex::partial_ordering::equivalent;
44 else if constexpr (exhaust_lhs)
46 if constexpr (dyn_rhs)
if (i ==
get_size(rhs))
return stdex::partial_ordering::equivalent;
47 return stdex::partial_ordering::less;
49 else if constexpr (exhaust_rhs)
51 if constexpr (dyn_lhs)
if (i ==
get_size(lhs))
return stdex::partial_ordering::equivalent;
52 return stdex::partial_ordering::greater;
56 if constexpr (dyn_lhs)
if (i ==
get_size(lhs))
return stdex::partial_ordering::less;
57 if constexpr (dyn_rhs)
if (i ==
get_size(rhs))
return stdex::partial_ordering::greater;
60 return fixed_lexicographical_compare<i + 1>(lhs, rhs);
72 template<collection Lhs, collection Rhs> requires
73 (collection_view<Lhs> or collection_view<Rhs>) and
74 (sized<Lhs> or sized<Rhs>)
76 template<
typename Lhs,
typename Rhs, std::enable_if_t<
77 collection<Lhs> and collection<Rhs> and
78 (collection_view<Lhs> or collection_view<Rhs>) and
79 (sized<Lhs> or sized<Rhs>),
int> = 0>
81 constexpr stdex::partial_ordering
87 return detail::fixed_lexicographical_compare(lhs, rhs);
89 else if constexpr (stdex::ranges::common_range<Lhs> and stdex::ranges::common_range<Rhs>)
92 stdex::ranges::begin(lhs),
93 stdex::ranges::end(lhs),
94 stdex::ranges::begin(rhs),
95 stdex::ranges::end(rhs));
99 auto f1 = stdex::ranges::begin(lhs);
100 const auto l1 = stdex::ranges::end(lhs);
101 auto f2 = stdex::ranges::begin(rhs);
102 const auto l2 = stdex::ranges::end(rhs);
103 bool exhaust1 = (f1 == l1);
104 bool exhaust2 = (f2 == l2);
105 for (; not exhaust1 and not exhaust2; exhaust1 = (++f1 == l1), exhaust2 = (++f2 == l2))
107 return !exhaust1 ? stdex::partial_ordering::greater:
108 !exhaust2 ? stdex::partial_ordering::less:
109 stdex::partial_ordering::equivalent;
Namespace for collections.
Definition: collections.hpp:27
Definition for collections::get.
Definition for collections::collection.
Definition: comparison.hpp:176
Definition for collections::size_of.
The size of a sized object (including a collection).
Definition: size_of.hpp:33
constexpr stdex::partial_ordering lexicographical_compare_three_way(const Lhs &lhs, const Rhs &rhs)
Compares two collections.
Definition: lexicographical_compare_three_way.hpp:82
Definition for collections::collection_view.
constexpr bool fixed_value_compares_with
T has a fixed value that compares with N in a particular way based on parameter comp.
Definition: fixed_value_compares_with.hpp:74
constexpr auto compare_three_way(A &&a, B &&b, const Comparison &c={})
Compare two coordinates::pattern objects lexicographically.
Definition: compare_three_way.hpp:142
Basic definitions for OpenKalman as a whole.
constexpr auto get_size(Arg &&arg)
Get the size of a sized object (e.g, a collection)
Definition: get_size.hpp:188