OpenKalman
collection_patterns_compare_with_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_COMPARE_WITH_DIMENSION_HPP
17 #define OPENKALMAN_PATTERNS_COLLECTION_PATTERNS_COMPARE_WITH_DIMENSION_HPP
18 
23 
24 namespace OpenKalman::patterns
25 {
26  namespace detail
27  {
28 #ifndef __cpp_concepts
29  template<typename T, typename = void>
30  struct has_common_collection_type : std::false_type {};
31 
32  template<typename T>
33  struct has_common_collection_type<T, std::void_t<typename collections::common_collection_type<T>::type>> : std::true_type {};
34 #endif
35 
36 
37  template<typename T, std::size_t dim, auto comp, std::size_t N, applicability b, typename = std::make_index_sequence<N>>
39 
40  template<typename T, std::size_t dim, auto comp, std::size_t N, applicability b, std::size_t...i>
41  struct collection_patterns_compare_with_dimension_fixed_size<T, dim, comp, N, b, std::index_sequence<i...>>
42  : std::bool_constant<(... and values::size_compares_with<
43  dimension_of<pattern_collection_element_t<i, T>>,
44  std::integral_constant<std::size_t, dim>,
45  comp, b>)> {};
46 
47 
48  template<typename T, std::size_t dim, auto comp, auto N, applicability b>
49  constexpr bool
50  collection_patterns_compare_with_dimension_impl()
51  {
52  if constexpr (values::fixed_value_compares_with<collections::size_of<T>, stdex::dynamic_extent, &stdex::is_neq>)
53  {
54 #ifdef __cpp_concepts
55  if constexpr (stdex::same_as<std::decay_t<decltype(N)>, values::unbounded_size_t>)
56 #else
57  if constexpr (N == std::size_t(values::unbounded_size))
58 #endif
60  else
62  }
63 #ifdef __cpp_concepts
64  else if constexpr (requires { typename collections::common_collection_type<T>::type; })
65 #else
66  else if constexpr (has_common_collection_type<T>::value)
67 #endif
68  {
71  std::integral_constant<std::size_t, dim>, comp, b>;
72  }
73  else
74  {
75  return b == applicability::permitted;
76  }
77  }
78 
79  }
80 
81 
87 #ifdef __cpp_concepts
88  template<
89  typename T,
90  std::size_t dim,
91  auto comp = &stdex::is_eq,
92  auto N = values::unbounded_size,
95  (values::integral<decltype(N)> or stdex::same_as<std::decay_t<decltype(N)>, values::unbounded_size_t>) and
96  (not values::integral<decltype(N)> or N > 0) and
97 #else
98  template<typename T, std::size_t dim, auto comp = &stdex::is_eq, std::size_t N = values::unbounded_size, applicability b = applicability::guaranteed>
99  constexpr inline bool collection_patterns_compare_with_dimension =
100  (N == values::unbounded_size or N > 0) and
101 #endif
102  pattern_collection<T> and
103  detail::collection_patterns_compare_with_dimension_impl<T, dim, comp, N, b>();
104 
105 
106 }
107 
108 #endif
Definition for pattern_collection.
The size of a patterns::pattern.
Definition: dimension_of.hpp:36
The concept, trait, or restraint represents a compile-time guarantee.
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: collection_patterns_compare_with_dimension.hpp:38
constexpr bool value
T is a fixed or dynamic value that is reducible to a number.
Definition: value.hpp:45
Definition: collection_patterns_compare_with_dimension.hpp:30
The namespace for features relating to patterns::pattern object.
Definition: collection_compares_with.hpp:24
constexpr bool collection_patterns_compare_with_dimension
Specifies that each element of a pattern_collection T has dimension dim for the first N indices...
Definition: collection_patterns_compare_with_dimension.hpp:99
Inclusion file for collections.
A type reflecting an unbound size.
Definition: size.hpp:27
constexpr bool size_compares_with
T and U are sizes that compare in a particular way based on parameter comp.
Definition: size_compares_with.hpp:98
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 collections::pattern_collection_element.
The common type within a collection, if it exists.
Definition: common_collection_type.hpp:34
Definition for patterns::dimension_of.