OpenKalman
max_tensor_order.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-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_MAX_TENSOR_ORDER_HPP
17 #define OPENKALMAN_MAX_TENSOR_ORDER_HPP
18 
20 
21 namespace OpenKalman
22 {
23  namespace detail
24  {
25  template<std::size_t i, typename T>
26  constexpr std::size_t max_tensor_order_impl(std::size_t result = 0)
27  {
28  if constexpr (i == 0) return result;
29  else if constexpr (dimension_size_of_index_is<T, i - 1, 1>) return max_tensor_order_impl<i - 1, T>(result);
30  else if constexpr (dimension_size_of_index_is<T, i - 1, 0>) return 0;
31  else return max_tensor_order_impl<i - 1, T>(result + 1);
32  }
33  }
34 
35 
43 #ifdef __cpp_concepts
44  template<typename T>
45 #else
46  template<typename T, typename = void>
47 #endif
49  : std::integral_constant<std::size_t, indexible<T> ? stdex::dynamic_extent : 0> {};
50 
51 
52 #ifdef __cpp_concepts
53  template<typename T> requires (index_count_v<T> != std::dynamic_extent)
54  struct max_tensor_order<T>
55 #else
56  template<typename T>
57  struct max_tensor_order<T, std::enable_if_t<index_count<T>::value != stdex::dynamic_extent>>
58 #endif
59  : std::integral_constant<std::size_t, detail::max_tensor_order_impl<index_count_v<T>, T>()> {};
60 
61 
65  template<typename T>
66  static constexpr std::size_t max_tensor_order_v = max_tensor_order<T>::value;
67 
68 
69 }
70 
71 #endif
The maximum number of indices of structure T of size other than 1 (including any dynamic indices)...
Definition: max_tensor_order.hpp:48
Definition for dimension_size_of_index_is.
The root namespace for OpenKalman.
Definition: basics.hpp:34
constexpr bool dimension_size_of_index_is
Specifies that a given index of T has a specified size.
Definition: dimension_size_of_index_is.hpp:35