OpenKalman
patterns_match.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) 2022-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_VECTOR_SPACE_DESCRIPTORS_MATCH_HPP
17 #define OPENKALMAN_VECTOR_SPACE_DESCRIPTORS_MATCH_HPP
18 
22 
23 namespace OpenKalman
24 {
25 
26  namespace detail
27  {
28  template<std::size_t...Is>
29  constexpr bool patterns_match_impl(std::index_sequence<Is...>) { return true; }
30 
31  template<std::size_t...Is, typename T, typename...Ts>
32  constexpr bool patterns_match_impl(std::index_sequence<Is...>, const T& t, const Ts&...ts)
33  {
34  return ([](auto I_const, const T& t, const Ts&...ts){
35  constexpr std::size_t I = decltype(I_const)::value;
36  return ((coordinates::compare(get_index_pattern<I>(t), get_index_pattern<I>(ts))) and ...);
37  }(std::integral_constant<std::size_t, Is>{}, t, ts...) and ...);
38  }
39 
40 
41  constexpr bool patterns_match_dyn_impl() { return true; }
42 
43  template<typename T, typename...Ts>
44  constexpr bool patterns_match_dyn_impl(const T& t, const Ts&...ts)
45  {
46  auto count = std::max({static_cast<std::size_t>(count_indices(t)), static_cast<std::size_t>(count_indices(ts))...});
47  for (std::size_t i = 0; i < count; ++i)
48  if (((coordinates::compare<&stdex::is_neq>(get_index_pattern(t, i), get_index_pattern(ts, i))) or ...)) return false;
49  return true;
50  }
51  }
52 
53 
60 #ifdef __cpp_concepts
61  template<indexible...Ts>
62 #else
63  template<typename...Ts, std::enable_if_t<(indexible<Ts> and ...), int> = 0>
64 #endif
65  constexpr bool patterns_match(const Ts&...ts)
66  {
67  if constexpr ((... and (index_count_v<Ts> != stdex::dynamic_extent)))
68  {
69  constexpr std::make_index_sequence<std::max({index_count_v<Ts>...})> seq;
70  return detail::patterns_match_impl(seq, ts...);
71  }
72  else
73  {
74  return detail::patterns_match_dyn_impl(ts...);
75  }
76  }
77 
78 }
79 
80 #endif
constexpr auto compare(const A &a, const B &b)
Compare two coordinates::pattern objects lexicographically.
Definition: compare.hpp:40
constexpr auto count_indices(const T &)
Get the number of indices necessary to address all the components of an indexible object...
Definition: count_indices.hpp:51
constexpr bool indexible
T is a multidimensional array type.
Definition: indexible.hpp:32
constexpr bool value
T is a fixed or dynamic value that is reducible to a number.
Definition: value.hpp:45
Definition of count_indices.
The root namespace for OpenKalman.
Definition: basics.hpp:34
constexpr bool patterns_match(const Ts &...ts)
Return true if every set of coordinates::pattern of a set of objects are equivalent.
Definition: patterns_match.hpp:65
Definition for index_count.
Definition of get_index_pattern function.
Definition: trait_backports.hpp:64
decltype(auto) constexpr get_index_pattern(T &&t, I i={})
Get the coordinates::pattern associated with indexible object T at a given index. ...
Definition: get_index_pattern.hpp:41