OpenKalman
one_dimensional.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_ONE_DIMENSIONAL_HPP
17 #define OPENKALMAN_ONE_DIMENSIONAL_HPP
18 
19 #include "patterns/patterns.hpp"
23 
24 namespace OpenKalman
25 {
26  namespace detail
27  {
28 #ifndef __cpp_concepts
29  template<typename T, auto N, applicability b, typename = void>
30  struct one_dimensional_impl : std::false_type {};
31 
32  template<typename T, auto N, applicability b>
33  struct one_dimensional_impl<T, N, b, std::enable_if_t<
34  patterns::collection_patterns_compare_with_dimension<typename pattern_collection_type_of<T>::type, 1, &stdex::is_eq, N, b>>>
35  : std::true_type {};
36 #endif
37 
38 
39  template<typename T, std::size_t N, typename = std::make_index_sequence<N>>
40  struct any_1d_index_impl : std::false_type {};
41 
42  template<typename T, std::size_t N, std::size_t...i>
43  struct any_1d_index_impl<T, N, std::index_sequence<i...>>
44  : std::bool_constant<(... or dimension_size_of_index_is<T, i, 1>)> {};
45 
46 
47  template<typename T, auto N>
48  constexpr bool
49  any_1d_index()
50  {
51 #ifdef __cpp_concepts
52  if constexpr (stdex::same_as<std::decay_t<decltype(N)>, values::unbounded_size_t>)
53 #else
54  if constexpr (N == std::size_t(values::unbounded_size))
55 #endif
56  {
57  if constexpr (values::fixed<index_count<T>>)
59  else
60  return false;
61  }
63  }
64  }
65 
66 
72 #ifdef __cpp_concepts
73  template<typename T, auto N = values::unbounded_size, applicability b = applicability::guaranteed>
74  concept one_dimensional =
75  indexible<T> and
76  (values::integral<decltype(N)> or stdex::same_as<std::decay_t<decltype(N)>, values::unbounded_size_t>) and
77  (not values::integral<decltype(N)> or N >= 0) and
79  (square_shaped<T, N> and detail::any_1d_index<T, N>()));
80 #else
81  template<typename T, std::size_t N = values::unbounded_size, applicability b = applicability::guaranteed>
82  constexpr inline bool one_dimensional =
83  indexible<T> and
84  (N == values::unbounded_size or N >= 0) and
85  detail::one_dimensional_impl<T, N, b>::value or
86  (square_shaped<T, N> and detail::any_1d_index<T, N>());
87 #endif
88 
89 
90 }
91 
92 #endif
typename pattern_collection_type_of< T >::type pattern_collection_type_of_t
helper template for pattern_collection_type_of.
Definition: pattern_collection_type_of.hpp:55
Definition for square_shaped.
Definition for pattern_collection_type_of.
constexpr bool square_shaped
At least 2 and at most N indices have the same extent.
Definition: square_shaped.hpp:91
constexpr bool value
T is a fixed or dynamic value that is reducible to a number.
Definition: value.hpp:45
Definition for dimension_size_of_index_is.
The root namespace for OpenKalman.
Definition: basics.hpp:34
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
Definition: one_dimensional.hpp:30
A type reflecting an unbound size.
Definition: size.hpp:27
constexpr bool integral
T is an integral value.
Definition: integral.hpp:47
constexpr bool one_dimensional
Specifies that a type is one-dimensional in each of the first N indices.
Definition: one_dimensional.hpp:82
constexpr unbounded_size_t unbounded_size
An instance of unbounded_size_t;.
Definition: size.hpp:60
constexpr bool fixed
T has a value that is determinable at compile time.
Definition: fixed.hpp:65
The minimum number of indices needed to access all the components of an object (i.e., the rank or order).
Definition: index_count.hpp:34
Definition: one_dimensional.hpp:40