OpenKalman
get_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) 2020-2025 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_COORDINATES_GET_DIMENSION_HPP
17 #define OPENKALMAN_COORDINATES_GET_DIMENSION_HPP
18 
19 #include <functional>
20 #include "../../../basics/compatibility/language-features.hpp"
26 
28 {
29  namespace detail
30  {
31  template<std::size_t i = 0, typename Tup>
32  static constexpr auto get_dimension_tuple(const Tup& tup)
33  {
34  if constexpr (i < std::tuple_size_v<Tup>)
35  {
36  return values::operation {std::plus{},
37  internal::get_descriptor_dimension(OpenKalman::internal::generalized_std_get<i>(tup)),
38  get_dimension_tuple<i + 1>(tup)};
39  }
40  else return std::integral_constant<std::size_t, 0_uz>{};
41  }
42  } // namespace detail
43 
44 
48 #ifdef __cpp_concepts
49  template<pattern Arg>
50  constexpr values::index auto
51 #else
52  template<typename Arg, std::enable_if_t<pattern<Arg>, int> = 0>
53  constexpr auto
54 #endif
55  get_dimension(const Arg& arg)
56  {
57  if constexpr (descriptor<Arg>)
58  {
59  return internal::get_descriptor_dimension(arg);
60  }
61  else if constexpr (collections::tuple_like<Arg>)
62  {
63  return detail::get_dimension_tuple(arg);
64  }
65  else
66  {
67  std::size_t ret = 0_uz;
68  for (auto& c : arg) ret += internal::get_descriptor_dimension(c);
69  return ret;
70  }
71  }
72 
73 
74 } // namespace OpenKalman::coordinates
75 
76 
77 #endif //OPENKALMAN_COORDINATES_GET_DIMENSION_HPP
Definition for collections::tuple_like.
Definition for coordinates::pattern.
constexpr auto get_dimension(const Arg &arg)
Get the vector dimension of coordinates::pattern Arg.
Definition: get_dimension.hpp:55
Definition for coordinates::descriptor.
Definition: compares_with.hpp:28
constexpr bool index
T is an index value.
Definition: index.hpp:56
operation(const Operation &, const Args &...) -> operation< Operation, Args... >
Deduction guide.