OpenKalman
vector.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-2023 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_HPP
17 #define OPENKALMAN_VECTOR_HPP
18 
19 
20 namespace OpenKalman
21 {
22  namespace detail
23  {
24  template<typename T, std::size_t N, Applicability b, std::size_t...Is>
25  constexpr bool do_vector_impl(std::index_sequence<Is...>)
26  {
27  return (... and (N == Is or (b == Applicability::permitted and dynamic_dimension<T, Is>) or dimension_size_of_index_is<T, Is, 1>));
28  }
29 
30 
31  // If index_count<T> is dynamic, at least check indices until N + 1.
32 #ifdef __cpp_concepts
33  template<typename T, std::size_t N, Applicability b>
34 #else
35  template<typename T, std::size_t N, Applicability b, typename = void>
36 #endif
37  struct vector_impl : std::bool_constant<
38  b == Applicability::permitted and detail::do_vector_impl<T, N, b>(std::make_index_sequence<N + 1> {})> {};
39 
40  // If index_count<T> is static, check all indices.
41 #ifdef __cpp_concepts
42  template<typename T, std::size_t N, Applicability b> requires (index_count_v<T> != dynamic_size)
43  struct vector_impl<T, N, b>
44 #else
45  template<typename T, std::size_t N, Applicability b>
46  struct vector_impl<T, N, b, std::enable_if_t<index_count<T>::value != dynamic_size>>
47 #endif
48  : std::bool_constant<detail::do_vector_impl<T, N, b>(std::make_index_sequence<index_count_v<T>> {})> {};
49 
50 
51  } // namespace detail
52 
53 
63  template<typename T, std::size_t N = 0, Applicability b = Applicability::guaranteed>
64 #ifdef __cpp_concepts
65  concept vector =
66 #else
67  constexpr bool vector =
68 #endif
69  indexible<T> and detail::vector_impl<T, N, b>::value;
70 
71 
72 } // namespace OpenKalman
73 
74 #endif //OPENKALMAN_VECTOR_HPP
The root namespace for OpenKalman.
Definition: basics.hpp:34
The concept, trait, or restraint is permitted, but whether it applies is not necessarily known at com...
Applicability
The applicability of a concept, trait, or restraint.
Definition: global-definitions.hpp:93
Definition: vector.hpp:37
constexpr std::size_t dynamic_size
A constant indicating that a size or index is dynamic.
Definition: global-definitions.hpp:33
constexpr bool vector
T is a vector (e.g., column or row vector).
Definition: vector.hpp:67