OpenKalman
pattern_collection_compares_with.hpp
Go to the documentation of this file.
1 /* This file is part of OpenKalman, a header-only C++ library for
2  * Kalman filters and other recursive filters.
3  *
4  * Copyright (c) 2019-2025 Christopher Lee Ogden <ogden@gatech.edu>
5  *
6  * This Source Code Form is subject to the terms of the Mozilla Public
7  * License, v. 2.0. If a copy of the MPL was not distributed with this
8  * file, You can obtain one at https://mozilla.org/MPL/2.0/.
9  */
10 
16 #ifndef OPENKALMAN_COORDINATE_PATTERN_COLLECTION_COMPARES_WITH_HPP
17 #define OPENKALMAN_COORDINATE_PATTERN_COLLECTION_COMPARES_WITH_HPP
18 
20 #include "pattern_collection.hpp"
21 #include "compares_with.hpp"
23 
25 {
26  namespace detail
27  {
28  template<typename T, typename PU, auto comp, applicability a, std::size_t i = 0>
29  constexpr bool
30  pattern_collection_compares_with_iter_T()
31  {
32  if constexpr (i < collections::size_of_v<T>)
33  {
34  using Ti = std::decay_t<collections::collection_element_t<i, T>>;
35  if constexpr (compares_with<Ti, PU, comp, a>)
36  return pattern_collection_compares_with_iter_T<T, PU, comp, a, i + 1>();
37  else
38  return false;
39  }
40  else
41  {
42  return true;
43  }
44  }
45 
46 
47  template<typename PT, typename U, auto comp, applicability a, std::size_t i = 0>
48  constexpr bool
49  pattern_collection_compares_with_iter_U()
50  {
51  if constexpr (i < collections::size_of_v<U>)
52  {
53  using Ui = std::decay_t<collections::collection_element_t<i, U>>;
54  if constexpr (compares_with<PT, Ui, comp, a>)
55  return pattern_collection_compares_with_iter_U<PT, U, comp, a, i + 1>();
56  else
57  return false;
58  }
59  else
60  {
61  return true;
62  }
63  }
64 
65 
66  template<typename T, typename U, auto comp, applicability a, std::size_t i = 0>
67  constexpr bool
68  pattern_collection_compares_with_iter()
69  {
70  if constexpr (i < collections::size_of_v<T>)
71  {
72  if constexpr (i < collections::size_of_v<U>)
73  {
74  using Ti = std::decay_t<collections::collection_element_t<i, T>>;
75  using Ui = std::decay_t<collections::collection_element_t<i, U>>;
76  if constexpr (compares_with<Ti, Ui, comp, a>)
77  return pattern_collection_compares_with_iter<T, U, comp, a, i + 1>();
78  else
79  return false;
80  }
81  else
82  {
83  return pattern_collection_compares_with_iter_T<T, Dimensions<1>, comp, a, i>();
84  }
85  }
86  else if constexpr (i < collections::size_of_v<U>)
87  {
88  return pattern_collection_compares_with_iter_U<Dimensions<1>, U, comp, a, i>();
89  }
90  else
91  {
92  return true;
93  }
94  }
95 
96 
97  template<typename T, typename U, auto comp, applicability a>
98  constexpr bool
99  pattern_collection_compares_with_impl()
100  {
101  constexpr bool fixed_t = collections::sized<T> and not values::fixed_value_compares_with<collections::size_of<T>, stdex::dynamic_extent>;
102  constexpr bool fixed_u = collections::sized<U> and not values::fixed_value_compares_with<collections::size_of<U>, stdex::dynamic_extent>;
103  if constexpr (fixed_t and fixed_u)
104  {
105  return detail::pattern_collection_compares_with_iter<T, U, comp, a>();
106  }
107  else if constexpr (fixed_t)
108  {
109  return detail::pattern_collection_compares_with_iter_T<T, stdex::ranges::range_value_t<U>, comp, a>();
110  }
111  else if constexpr (fixed_u)
112  {
113  return detail::pattern_collection_compares_with_iter_U<stdex::ranges::range_value_t<T>, U, comp, a>();
114  }
115  else
116  {
117  return compares_with<stdex::ranges::range_value_t<T>, stdex::ranges::range_value_t<U>, comp, a>;
118  }
119  }
120 
121  }
122 
123 
130  template<typename T, typename U, auto comp = &stdex::is_eq, applicability a = applicability::guaranteed>
131 #ifdef __cpp_concepts
133 #else
134  constexpr bool pattern_collection_compares_with =
135 #endif
136  pattern_collection<T> and pattern_collection<U> and
137  std::is_invocable_r_v<bool, decltype(comp), stdex::partial_ordering> and
138  detail::pattern_collection_compares_with_impl<T, U, comp, a>();
139 
140 
141 }
142 
143 #endif
Definition for pattern_collection.
Definition for compares_with.
Definition of the Dimensions class.
The namespace for features relating to coordinates::pattern object.
Definition: compares_with.hpp:25
Inclusion file for collections.
constexpr bool pattern_collection_compares_with
Compares a two coordinates::pattern_collection objects.
Definition: pattern_collection_compares_with.hpp:134