OpenKalman
get_singular_component.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_GET_SINGULAR_COMPONENT_HPP
17 #define OPENKALMAN_GET_SINGULAR_COMPONENT_HPP
18 
19 
20 namespace OpenKalman::internal
21 {
22  namespace detail
23  {
24  template<typename Arg, typename Indices>
25  constexpr decltype(auto)
26  get_singular_component_impl(Arg &&arg, const Indices &indices)
27  {
28  using Trait = interface::library_interface<std::decay_t<Arg>>;
29  return Trait::get_component(std::forward<Arg>(arg), internal::truncate_indices(indices, count_indices(arg)))
30  }
31 
32 
33  template<typename Arg, std::size_t...Ix>
34  constexpr decltype(auto)
35  get_singular_component_impl(Arg &&arg, std::index_sequence<Ix...>)
36  {
37  auto indices = std::array<std::size_t, sizeof...(Ix)>{static_cast<decltype(Ix)>(0)...};
38  return detail::get_singular_component_impl(std::forward<Arg>(arg), indices);
39  }
40  } // namespace detail
41 
42 
48  template<typename Arg>
49  constexpr decltype(auto)
50  get_singular_component(Arg&& arg)
51  {
52  if constexpr (index_count_v<Arg> == dynamic_size)
53  return detail::get_singular_component_impl(std::forward<Arg>(arg), std::vector<std::size_t>{count_indices(arg), 0});
54  else
55  return detail::get_singular_component_impl(std::forward<Arg>(arg), std::make_index_sequence<index_count_v<Arg>>{});
56  }
57 
58 
59 } // namespace OpenKalman::internal
60 
61 #endif //OPENKALMAN_GET_SINGULAR_COMPONENT_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
Definition: tuple_reverse.hpp:103
decltype(auto) constexpr get_component(Arg &&arg, const Indices &indices)
Get a component of an object at a particular set of indices.
Definition: get_component.hpp:54
constexpr std::size_t dynamic_size
A constant indicating that a size or index is dynamic.
Definition: global-definitions.hpp:33
Definition: basics.hpp:48