OpenKalman
dynamic_index_count.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-2024 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_DYNAMIC_INDEX_COUNT_HPP
17 #define OPENKALMAN_DYNAMIC_INDEX_COUNT_HPP
18 
19 
20 namespace OpenKalman
21 {
22  namespace detail
23  {
24  template<typename T, std::size_t...I>
25  constexpr std::size_t dynamic_index_count_impl(std::index_sequence<I...>)
26  {
27  return ((dynamic_dimension<T, I> ? 1 : 0) + ... + 0);
28  }
29  }
30 
31 
36 #ifdef __cpp_concepts
37  template<indexible T>
38 #else
39  template<typename T, typename = void>
40 #endif
41  struct dynamic_index_count : std::integral_constant<std::size_t, dynamic_size> {};
42 
43 
48 #ifdef __cpp_concepts
49  template<indexible T> requires (index_count_v<T> != dynamic_size)
50  struct dynamic_index_count<T>
51 #else
52  template<typename T>
53  struct dynamic_index_count<T, std::enable_if_t<(index_count<T>::value != dynamic_size)>>
54 #endif
55  : std::integral_constant<std::size_t, detail::dynamic_index_count_impl<T>(std::make_index_sequence<index_count_v<T>> {})> {};
56 
57 
61 #ifdef __cpp_concepts
62  template<indexible T>
63 #else
64  template<typename T>
65 #endif
66  static constexpr std::size_t dynamic_index_count_v = dynamic_index_count<T>::value;
67 
68 
69 } // namespace OpenKalman
70 
71 #endif //OPENKALMAN_DYNAMIC_INDEX_COUNT_HPP
Counts the number of indices of T in which the dimensions are dynamic.
Definition: dynamic_index_count.hpp:41
Definition: tuple_reverse.hpp:103
The root namespace for OpenKalman.
Definition: basics.hpp:34
constexpr std::size_t dynamic_size
A constant indicating that a size or index is dynamic.
Definition: global-definitions.hpp:33