OpenKalman
get_index_extent.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_GET_INDEX_EXTENT_HPP
17 #define OPENKALMAN_GET_INDEX_EXTENT_HPP
18 
22 
23 namespace OpenKalman
24 {
28 #ifdef __cpp_concepts
29  template<indexible T, values::index I = std::integral_constant<std::size_t, 0>>
30  constexpr values::index auto
31 #else
32  template<typename T, typename I = std::integral_constant<std::size_t, 0>,
33  std::enable_if_t<indexible<T> and values::index<I>, int> = 0>
34  constexpr auto
35 #endif
36  get_index_extent(T&& t, I i = I{})
37  {
38  if constexpr (values::size_compares_with<I, index_count<T>, &stdex::is_gteq>)
39  {
40  return std::integral_constant<std::size_t, 1>{};
41  }
42  else if constexpr (values::size_compares_with<I, index_count<T>, &stdex::is_lt>)
43  {
44  constexpr auto ex = std::decay_t<decltype(get_mdspan(t))>::static_extent(i);
45  if constexpr (ex == stdex::dynamic_extent)
46  return get_mdspan(t).extent(static_cast<std::size_t>(i));
47  else
48  return std::integral_constant<std::size_t, ex>{};
49  }
50  else if (i < count_indices(t))
51  {
52  return get_mdspan(t).extent(static_cast<std::size_t>(i));
53  }
54  else
55  {
56  return 1_uz;
57  }
58  }
59 
60 
64 #ifdef __cpp_concepts
65  template<std::size_t I, indexible T>
66  constexpr values::index auto
67 #else
68  template<std::size_t I, typename T, std::enable_if_t<indexible<T>, int> = 0>
69  constexpr auto
70 #endif
72  {
73  return get_index_extent(t, std::integral_constant<std::size_t, I>{});
74  }
75 
76 }
77 
78 #endif
constexpr auto get_mdspan(T &t)
Get the coordinates::pattern_collection associated with indexible object T.
Definition: get_mdspan.hpp:35
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
Definition of count_indices.
constexpr auto get_index_extent(T &&t, I i=I{})
Get the runtime dimensions of index N of indexible T.
Definition: get_index_extent.hpp:36
The root namespace for OpenKalman.
Definition: basics.hpp:34
Definition of get_mdspan function.
constexpr bool size_compares_with
T and U are sizes that compare in a particular way based on parameter comp.
Definition: size_compares_with.hpp:98
Definition for index_count.
constexpr bool index
T is an index value.
Definition: index.hpp:62
The minimum number of indices needed to access all the components of an object (i.e., the rank or order).
Definition: index_count.hpp:34