OpenKalman
collection_patterns_have_same_dimension.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) 2025-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_PATTERNS_HAVE_SAME_DIMENSION_HPP
17 #define OPENKALMAN_PATTERNS_COLLECTION_PATTERNS_HAVE_SAME_DIMENSION_HPP
18 
25 
26 namespace OpenKalman::patterns
27 {
28  namespace detail
29  {
30 #ifndef __cpp_concepts
31  template<typename T, typename = void>
32  struct patt_dim_is_fixed_2 : std::false_type {};
33 
34  template<typename T>
35  struct patt_dim_is_fixed_2<T, std::enable_if_t<fixed_pattern<typename T::type>>>
36  : std::true_type {};
37 #endif
38 
39 
40  template<typename T, std::size_t N, std::size_t i = 0>
41  constexpr std::size_t
42  best_comparison_dim()
43  {
44  if constexpr (i < N)
45  {
47  if constexpr (fixed_pattern<P>) return dimension_of_v<P>;
48  else return best_comparison_dim<T, N, i + 1>();
49  }
50  else
51  {
52  return stdex::dynamic_extent;
53  }
54  }
55 
56 
57  template<typename T, std::size_t N, applicability b, typename = std::make_index_sequence<N>>
58  struct collection_dim_comp_fixed : std::false_type {};
59 
60  template<typename T, std::size_t N, applicability b, std::size_t...i>
61  struct collection_dim_comp_fixed<T, N, b, std::index_sequence<i...>>
62  : std::bool_constant<(... and values::size_compares_with<
63  dimension_of<pattern_collection_element_t<i, T>>,
64  std::integral_constant<std::size_t, best_comparison_dim<T, N>()>,
65  &stdex::is_eq, b>)> {};
66 
67 
68  template<typename T, auto N, applicability b>
69  constexpr bool
70  collection_patterns_have_same_dimension_impl()
71  {
72  constexpr bool n_lt_2 = []{
73 #ifdef __cpp_concepts
74  if constexpr (stdex::same_as<std::decay_t<decltype(N)>, values::unbounded_size_t>) return false;
75 #else
76  if constexpr (N == std::size_t(values::unbounded_size)) return false;
77 #endif
78  else return N < 2;
79  }();
80 
81  if constexpr (values::fixed_value_compares_with<collections::size_of<T>, stdex::dynamic_extent, &stdex::is_neq>)
82  {
83 #ifdef __cpp_concepts
84  if constexpr (stdex::same_as<std::decay_t<decltype(N)>, values::unbounded_size_t>)
85 #else
86  if constexpr (N == std::size_t(values::unbounded_size))
87 #endif
89  else
91  }
92  else
93  {
94  return n_lt_2 or
95 #ifdef __cpp_concepts
96  requires { requires fixed_pattern<collections::common_collection_type_t<T>>; } or
97 #else
99 #endif
101  }
102  }
103 
104  }
105 
106 
114 #ifdef __cpp_concepts
115  template<typename T, auto N = values::unbounded_size, applicability b = applicability::guaranteed>
117  (values::integral<decltype(N)> or stdex::same_as<std::decay_t<decltype(N)>, values::unbounded_size_t>) and
118  (not values::integral<decltype(N)> or N > 0) and
119 #else
120  template<typename T, std::size_t N = values::unbounded_size, applicability b = applicability::guaranteed>
121  constexpr inline bool collection_patterns_have_same_dimension =
122  (N == values::unbounded_size or N > 0) and
123 #endif
124  pattern_collection<T> and
125  detail::collection_patterns_have_same_dimension_impl<T, N, b>();
126 
127 
128 }
129 
130 #endif
Definition for pattern_collection.
applicability
The applicability of a concept, trait, or restraint.
Definition: constants.hpp:35
The concept, trait, or restraint is permitted, but whether it applies is not necessarily known at com...
Definition for patterns::fixed_pattern.
constexpr bool value
T is a fixed or dynamic value that is reducible to a number.
Definition: value.hpp:45
constexpr bool collection_patterns_have_same_dimension
Specifies that the first N elements of a pattern_collection have the same dimensions.
Definition: collection_patterns_have_same_dimension.hpp:121
typename pattern_collection_element< i, T >::type pattern_collection_element_t
Helper template for collection_element.
Definition: pattern_collection_element.hpp:58
Definition: collection_patterns_have_same_dimension.hpp:32
The namespace for features relating to patterns::pattern object.
Definition: collection_compares_with.hpp:24
Inclusion file for collections.
A type reflecting an unbound size.
Definition: size.hpp:27
Definition: collection_patterns_have_same_dimension.hpp:58
constexpr bool integral
T is an integral value.
Definition: integral.hpp:47
constexpr bool fixed_value_compares_with
T has a fixed value that compares with N in a particular way based on parameter comp.
Definition: fixed_value_compares_with.hpp:74
constexpr unbounded_size_t unbounded_size
An instance of unbounded_size_t;.
Definition: size.hpp:60
Definition for patterns::get_common_pattern_collection_dimension.
Definition for collections::pattern_collection_element.
Definition for patterns::dimension_of.