OpenKalman
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) 2019-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_INDEX_COUNT_HPP
17 #define OPENKALMAN_INDEX_COUNT_HPP
18 
19 
20 namespace OpenKalman
21 {
28 #ifdef __cpp_concepts
29  template<typename T>
30 #else
31  template<typename T, typename = void>
32 #endif
33  struct index_count;
34 
35 
36 #ifndef __cpp_concepts
37  namespace detail
38  {
39  template<typename T, typename = void>
40  struct static_count_indices_defined : std::false_type {};
41 
42  template<typename T>
43  struct static_count_indices_defined<T, std::enable_if_t<interface::count_indices_defined_for<T>>>
44  : std::bool_constant<values::fixed<decltype(count_indices(std::declval<T>()))>> {};
45  }
46 #endif
47 
48 
52 #ifdef __cpp_concepts
53  template<typename T> requires requires(T t) { {count_indices(t)} -> values::fixed; }
54  struct index_count<T>
55 #else
56  template<typename T>
57  struct index_count<T, std::enable_if_t<detail::static_count_indices_defined<T>::value>>
58 #endif
59  : std::integral_constant<std::size_t, std::decay_t<decltype(count_indices(std::declval<T>()))>::value> {};
60 
61 
62 #ifndef __cpp_concepts
63  namespace detail
64  {
65  template<typename T, typename = void>
66  struct dynamic_count_indices_defined : std::false_type {};
67 
68  template<typename T>
69  struct dynamic_count_indices_defined<T, std::enable_if_t<interface::count_indices_defined_for<T>>>
70  : std::bool_constant<values::index<decltype(count_indices(std::declval<T>()))> and
71  values::dynamic<decltype(count_indices(std::declval<T>()))>> {};
72  }
73 #endif
74 
75 
79 #ifdef __cpp_concepts
80  template<typename T> requires requires(T t) { {count_indices(t)} -> values::dynamic; }
81  struct index_count<T>
82 #else
83  template<typename T>
84  struct index_count<T, std::enable_if_t<detail::dynamic_count_indices_defined<T>::value>>
85 #endif
86  : std::integral_constant<std::size_t, dynamic_size> {};
87 
88 
92  template<typename T>
93  static constexpr std::size_t index_count_v = index_count<T>::value;
94 
95 
96 } // namespace OpenKalman
97 
98 #endif //OPENKALMAN_INDEX_COUNT_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
The root namespace for OpenKalman.
Definition: basics.hpp:34
constexpr bool dynamic
T is a values::value that is not determinable at compile time.
Definition: dynamic.hpp:48
constexpr bool fixed
T is a values::value that is determinable at compile time.
Definition: fixed.hpp:60
The minimum number of indices need to access all the components of an object.
Definition: index_count.hpp:33