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 
20 
21 namespace OpenKalman
22 {
23  namespace detail
24  {
25  template<std::size_t N, std::size_t i = 0, typename T>
26  constexpr bool get_is_vector_impl(const T& t)
27  {
28  if constexpr (i < index_count_v<T>)
29  {
30  return values::operation(
31  std::logical_and{},
33  std::logical_or{},
34  std::bool_constant<N == i>{},
35  values::operation(std::equal_to{}, get_index_extent<i>(t), std::integral_constant<std::size_t, 1>{})
36  ),
37  get_is_vector_impl<N, i + 1>(t));
38  }
39  else
40  {
41  return std::true_type {};
42  }
43  }
44  }
45 
46 
53 #ifdef __cpp_concepts
54  template<std::size_t N = 0, indexible T>
55  constexpr internal::boolean_testable auto
56 #else
57  template<std::size_t N = 0, typename T, std::enable_if_t<indexible<T>, int> = 0>
58  constexpr auto
59 #endif
60  is_vector(const T& t)
61  {
62  if constexpr (index_count_v<T> == stdex::dynamic_extent)
63  {
64  for (std::size_t i = 0; i < count_indices(t); ++i)
65  if (N != i and get_index_extent(t, i) != 1) return false;
66  return true;
67  }
68  else
69  {
70  return detail::get_is_vector_impl<N>(t);
71  }
72  }
73 
74 
75 }
76 
77 #endif
constexpr auto count_indices(const T &)
Get the number of indices necessary to address all the components of an indexible object...
Definition: count_indices.hpp:51
constexpr auto get_index_extent(T &&t, I i=I{})
Get the runtime dimensions of index N of indexible T.
Definition: get_index_extent.hpp:36
The root namespace for OpenKalman.
Definition: basics.hpp:34
constexpr auto is_vector(const T &t)
Return true if T is a vector at runtime.
Definition: is_vector.hpp:60
Definition for index_count.
constexpr auto operation(Operation &&op, Args &&...args)
A potentially constant-evaluated operation involving some number of values.
Definition: operation.hpp:98