16 #ifndef OPENKALMAN_COLLECTION_COMPARE_INDICES_HPP 17 #define OPENKALMAN_COLLECTION_COMPARE_INDICES_HPP 28 template<
typename Lhs,
typename Rhs>
30 get_min_size(
const Lhs& lhs,
const Rhs& rhs)
32 if constexpr (sized<Lhs> and sized<Rhs>)
34 else if constexpr (sized<Lhs>)
41 template<
typename Lhs,
typename Rhs>
45 constexpr
bool fixed_lhs = values::fixed_value_compares_with<size_of<Lhs>, stdex::dynamic_extent, &stdex::is_neq>;
46 constexpr
bool fixed_rhs = values::fixed_value_compares_with<size_of<Rhs>, stdex::dynamic_extent, &stdex::is_neq>;
47 if constexpr (fixed_lhs and fixed_rhs)
48 return std::min(size_of_v<Lhs>, size_of_v<Rhs>);
49 else if constexpr (fixed_lhs)
50 return size_of_v<Lhs>;
51 else if constexpr (fixed_rhs)
52 return size_of_v<Rhs>;
54 return stdex::dynamic_extent;
58 template<auto comp, std::
size_t fsz, std::
size_t i = 0,
typename Lhs,
typename Rhs,
typename Sz>
60 compare_indices_fixed(
const Lhs& lhs,
const Rhs& rhs,
const Sz& sz)
62 using ix = std::integral_constant<std::size_t, i>;
65 if constexpr (values::size_compares_with<ix, Sz, &stdex::is_lt>)
69 compare_indices_fixed<comp, fsz, i + 1>(lhs, rhs, sz));
70 else if constexpr (values::size_compares_with<ix, Sz, &stdex::is_gteq> or i >= fsz)
71 return std::true_type {};
75 return c(collections::get<i>(lhs), collections::get<i>(rhs)) and
76 compare_indices_fixed<comp, fsz, i + 1>(lhs, rhs, sz);
91 template<auto comp = &stdex::is_eq, index Lhs, index Rhs> requires sized<Lhs> or sized<Rhs>
92 constexpr OpenKalman::internal::boolean_testable
auto 94 template<
auto comp = &stdex::is_eq,
typename Lhs,
typename Rhs, std::enable_if_t<
95 index<Lhs> and index<Rhs> and (sized<Lhs> or sized<Rhs>),
int> = 0>
100 auto sz = detail::get_min_size(lhs, rhs);
101 constexpr std::size_t fsz = detail::get_fixed_size<Lhs, Rhs>();
103 if constexpr (fsz != stdex::dynamic_extent)
105 return detail::compare_indices_fixed<comp, fsz>(lhs, rhs, sz);
109 for (std::size_t i = 0; i < sz; ++i)
Namespace for collections.
Definition: collections.hpp:27
Definition for collections::get.
Header file for code relating to values (e.g., scalars and indices)
Definition: comparison.hpp:176
Definition for collections::size_of.
constexpr auto compare_indices(const Lhs &lhs, const Rhs &rhs)
Performs an element-by-element comparison of two index collections.
Definition: compare_indices.hpp:98
decltype(auto) constexpr get_element(Arg &&arg, I i)
A generalization of std::get and the range subscript operator.
Definition: get_element.hpp:122
constexpr auto compare_three_way(A &&a, B &&b, const Comparison &c={})
Compare two coordinates::pattern objects lexicographically.
Definition: compare_three_way.hpp:142
Definition for collections::index.
constexpr auto get_size(Arg &&arg)
Get the size of a sized object (e.g, a collection)
Definition: get_size.hpp:188
constexpr auto operation(Operation &&op, Args &&...args)
A potentially constant-evaluated operation involving some number of values.
Definition: operation.hpp:98