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)
35 operator()(std::size_t a, std::size_t b)
const {
return std::min(a, b); }
38 if constexpr (sized<Lhs> and sized<Rhs>)
40 else if constexpr (sized<Lhs>)
47 template<
typename Lhs,
typename Rhs>
51 constexpr
bool fixed_lhs = values::fixed_value_compares_with<size_of<Lhs>, stdex::dynamic_extent, &stdex::is_neq>;
52 constexpr
bool fixed_rhs = values::fixed_value_compares_with<size_of<Rhs>, stdex::dynamic_extent, &stdex::is_neq>;
53 if constexpr (fixed_lhs and fixed_rhs)
54 return std::min(size_of_v<Lhs>, size_of_v<Rhs>);
55 else if constexpr (fixed_lhs)
56 return size_of_v<Lhs>;
57 else if constexpr (fixed_rhs)
58 return size_of_v<Rhs>;
60 return stdex::dynamic_extent;
67 template<
typename A,
typename B>
68 constexpr
auto operator()(
const A& a,
const B& b)
const 75 template<auto comp, std::
size_t fsz, std::
size_t i = 0,
typename Lhs,
typename Rhs,
typename Sz>
77 compare_indices_fixed(
const Lhs& lhs,
const Rhs& rhs,
const Sz& sz)
79 using ix = std::integral_constant<std::size_t, i>;
81 if constexpr (values::size_compares_with<ix, Sz, &stdex::is_lt>)
85 compare_indices_fixed<comp, fsz, i + 1>(lhs, rhs, sz));
86 else if constexpr (values::size_compares_with<ix, Sz, &stdex::is_gteq> or i >= fsz)
87 return std::true_type {};
92 compare_indices_fixed<comp, fsz, i + 1>(lhs, rhs, sz);
106 #ifdef __cpp_concepts 107 template<auto comp = &stdex::is_eq, index Lhs, index Rhs> requires sized<Lhs> or sized<Rhs>
108 constexpr OpenKalman::internal::boolean_testable
auto 110 template<
auto comp = &stdex::is_eq,
typename Lhs,
typename Rhs, std::enable_if_t<
111 index<Lhs> and index<Rhs> and (sized<Lhs> or sized<Rhs>),
int> = 0>
116 auto sz = detail::get_min_size(lhs, rhs);
117 constexpr std::size_t fsz = detail::get_fixed_size<Lhs, Rhs>();
119 if constexpr (fsz != stdex::dynamic_extent)
121 return detail::compare_indices_fixed<comp, fsz>(lhs, rhs, sz);
125 for (std::size_t i = 0; i < sz; ++i)
Namespace for collections.
Definition: collections.hpp:27
Definition for collections::get.
constexpr auto get_size(Arg &&arg)
Get the size of a sized object (e.g, a collection)
Definition: get_size.hpp:224
Header file for code relating to values (e.g., scalars and indices)
Definition: comparison.hpp:176
Definition for collections::size_of.
Definition: compare_indices.hpp:65
constexpr auto compare_indices(const Lhs &lhs, const Rhs &rhs)
Performs an element-by-element comparison of two index collections.
Definition: compare_indices.hpp:114
decltype(auto) constexpr get_element(Arg &&arg, I i)
A generalization of std::get and the range subscript operator.
Definition: get_element.hpp:124
Definition for collections::index.
constexpr auto operation(Operation &&op, Args &&...args)
A potentially constant-evaluated operation involving some number of values.
Definition: operation.hpp:98