OpenKalman
is_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) 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_IS_VECTOR_HPP
17 #define OPENKALMAN_IS_VECTOR_HPP
18 
19 
20 namespace OpenKalman
21 {
22  namespace detail
23  {
24  template<std::size_t N, std::size_t...Is, typename T>
25  constexpr bool get_is_vector_impl(std::index_sequence<Is...>, const T& t)
26  {
27  return (... and (N == Is or get_index_dimension_of<Is>(t) == 1));
28  }
29  }
30 
31 
39 #ifdef __cpp_concepts
40  template<std::size_t N = 0, interface::count_indices_defined_for T>
41 #else
42  template<std::size_t N = 0, typename T, std::enable_if_t<interface::count_indices_defined_for<T>, int> = 0>
43 #endif
44  constexpr bool is_vector(const T& t)
45  {
46  if constexpr (values::fixed<decltype(count_indices(t))>)
47  {
48  constexpr std::size_t count = std::decay_t<decltype(count_indices(t))>::value;
49  return detail::get_is_vector_impl<N>(std::make_index_sequence<count>{}, t);
50  }
51  else
52  {
53  for (std::size_t i = 0; i < count_indices(t); ++i) if (N != i and get_index_dimension_of(t, i) != 1) return false;
54  return true;
55  }
56  }
57 
58 
59 } // namespace OpenKalman
60 
61 #endif //OPENKALMAN_IS_VECTOR_HPP
constexpr auto count_indices(const T &t)
Get the number of indices available to address the components of an indexible object.
Definition: count_indices.hpp:33
constexpr bool value
T is numerical value or is reducible to a numerical value.
Definition: value.hpp:31
The root namespace for OpenKalman.
Definition: basics.hpp:34
constexpr bool is_vector(const T &t)
Return true if T is a vector at runtime.
Definition: is_vector.hpp:44
constexpr bool fixed
T is a values::value that is determinable at compile time.
Definition: fixed.hpp:60
constexpr auto get_index_dimension_of(const T &t, N n=N{})
Get the runtime dimensions of index N of indexible T.
Definition: get_index_dimension_of.hpp:34