OpenKalman
get_index_pattern.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) 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_PATTERN_HPP
17 #define OPENKALMAN_GET_INDEX_PATTERN_HPP
18 
19 #include "patterns/patterns.hpp"
25 
26 namespace OpenKalman
27 {
33 #ifdef __cpp_concepts
34  template<indexible T, values::index I = std::integral_constant<std::size_t, 0>>
35  constexpr patterns::pattern decltype(auto)
36 #else
37  template<typename T, typename I = std::integral_constant<std::size_t, 0>,
38  std::enable_if_t<indexible<T> and values::index<I>, int> = 0>
39  constexpr decltype(auto)
40 #endif
41  get_index_pattern(T&& t, I i = {})
42  {
43  if constexpr (interface::get_pattern_collection_defined_for<std::remove_reference_t<T>>)
44  {
45  return patterns::get_pattern(get_pattern_collection(std::forward<T>(t)), std::move(i));
46  }
47  else if constexpr (values::size_compares_with<I, index_count<T>, &stdex::is_lt>)
48  {
49  constexpr auto ex = std::decay_t<decltype(get_mdspan(t))>::static_extent(i);
50  if constexpr (ex == stdex::dynamic_extent)
51  return get_mdspan(t).extent(static_cast<std::size_t>(i));
52  else
53  return patterns::Dimensions<ex>{};
54  }
55  else if constexpr (values::size_compares_with<I, index_count<T>, &stdex::is_gteq>)
56  {
57  return patterns::Dimensions<1>{};
58  }
59  else if (i < count_indices(t))
60  {
61  return get_mdspan(t).extent(static_cast<std::size_t>(i));
62  }
63  else
64  {
65  return 1_uz;
66  }
67  }
68 
69 
73 #ifdef __cpp_concepts
74  template<std::size_t i, indexible T>
75  constexpr patterns::pattern auto
76 #else
77  template<std::size_t i, typename T, std::enable_if_t<indexible<T>, int> = 0>
78  constexpr auto
79 #endif
81  {
82  return get_index_pattern(t, std::integral_constant<std::size_t, i>{});
83  }
84 
85 }
86 
87 #endif
decltype(auto) constexpr get_pattern(P &&p, I i)
Get a pattern within a pattern_collection.
Definition: get_pattern.hpp:39
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
constexpr bool pattern
An object describing the characteristics (e.g., dimensions, wrapping structure) of an index...
Definition: pattern.hpp:31
decltype(auto) constexpr get_pattern_collection(T &&t)
Get the patterns::pattern_collection associated with indexible object T.
Definition: get_pattern_collection.hpp:36
Definition of count_indices.
A structure representing the dimensions associated with of a particular index.
Definition: Dimensions.hpp:42
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.
Definition of get_pattern_collection function.
decltype(auto) constexpr get_index_pattern(T &&t, I i={})
Get the patterns::pattern associated with indexible object T at a given index.
Definition: get_index_pattern.hpp:41
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
Concepts for testing whether object_traits or library_interface definitions exist for a particular ob...
decltype(auto) constexpr get_mdspan(T &&t)
Get the mdspan associated with indexible object T.
Definition: get_mdspan.hpp:35