OpenKalman
count_indices.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) 2022-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_COUNT_INDICES_HPP
17 #define OPENKALMAN_COUNT_INDICES_HPP
18 
19 #include "values/values.hpp"
22 
23 namespace OpenKalman
24 {
25  namespace detail
26  {
27  template<typename Mdspan, std::size_t i = Mdspan::rank()>
28  constexpr auto remove_trailing_1D_indices()
29  {
30  if constexpr (i == 0)
31  return std::integral_constant<std::size_t, i> {};
32  else if constexpr (Mdspan::static_extent(i - 1_uz) == 1_uz)
33  return remove_trailing_1D_indices<Mdspan, i - 1_uz>();
34  else
35  return std::integral_constant<std::size_t, i> {};
36  }
37  }
38 
39 
44 #ifdef __cpp_concepts
45  template<indexible T>
46  constexpr values::index auto
47 #else
48  template<typename T, std::enable_if_t<indexible<T>, int> = 0>
49  constexpr auto
50 #endif
51  count_indices(const T&)
52  {
53  using Mdspan = std::decay_t<decltype(get_mdspan(std::declval<const T&>()))>;
54  return detail::remove_trailing_1D_indices<Mdspan>();
55  }
56 
57 }
58 
59 #endif
Header file for code relating to values (e.g., scalars and indices)
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
The root namespace for OpenKalman.
Definition: basics.hpp:34
Definition of get_mdspan function.
constexpr bool index
T is an index value.
Definition: index.hpp:62
Definition for indexible.