OpenKalman
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-2026 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_PATTERNS_COLLECTION_COMPARES_WITH_HPP
17 #define OPENKALMAN_PATTERNS_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  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 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  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 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  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 collection_compares_with_iter<T, U, comp, a, i + 1>();
78  else
79  return false;
80  }
81  else
82  {
83  return 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 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  collection_compares_with_impl()
100  {
101 #ifndef __cpp_concepts
102  if constexpr (pattern_collection<T> and pattern_collection<U>) {
103 #endif
104  constexpr bool fixed_t = collections::sized<T> and not values::fixed_value_compares_with<collections::size_of<T>, stdex::dynamic_extent>;
105  constexpr bool fixed_u = collections::sized<U> and not values::fixed_value_compares_with<collections::size_of<U>, stdex::dynamic_extent>;
106  if constexpr (fixed_t and fixed_u)
107  return detail::collection_compares_with_iter<T, U, comp, a>();
108  else if constexpr (fixed_t)
109  return detail::collection_compares_with_iter_T<T, stdex::ranges::range_value_t<U>, comp, a>();
110  else if constexpr (fixed_u)
111  return detail::collection_compares_with_iter_U<stdex::ranges::range_value_t<T>, U, comp, a>();
112  else
113  return compares_with<stdex::ranges::range_value_t<T>, stdex::ranges::range_value_t<U>, comp, a>;
114 #ifndef __cpp_concepts
115  } else return false;
116 #endif
117  }
118 
119  }
120 
121 
128  template<typename T, typename U, auto comp = &stdex::is_eq, applicability a = applicability::guaranteed>
129 #ifdef __cpp_concepts
130  concept collection_compares_with =
131 #else
132  constexpr bool collection_compares_with =
133 #endif
134  pattern_collection<T> and pattern_collection<U> and
135  std::is_invocable_r_v<bool, decltype(comp), stdex::partial_ordering> and
136  detail::collection_compares_with_impl<T, U, comp, a>();
137 
138 
139 }
140 
141 #endif
Definition for pattern_collection.
Definition for compares_with.
Definition of the Dimensions class.
constexpr bool collection_compares_with
Compares two pattern_collection objects.
Definition: collection_compares_with.hpp:132
The namespace for features relating to patterns::pattern object.
Definition: collection_compares_with.hpp:24
Inclusion file for collections.