OpenKalman
get_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-2026 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_COLLECTIONS_GET_PATTERN_HPP
17 #define OPENKALMAN_COLLECTIONS_GET_PATTERN_HPP
18 
23 #include "patterns/descriptors/Any.hpp"
24 
25 namespace OpenKalman::patterns
26 {
31 #ifdef __cpp_concepts
32  template<pattern_collection P, values::index I>
33  constexpr pattern decltype(auto)
34 #else
35  template<typename P, typename I, std::enable_if_t<
36  pattern_collection<P> and values::index<I>, int> = 0>
37  constexpr decltype(auto)
38 #endif
39  get_pattern(P&& p, I i)
40  {
41  if constexpr (values::size_compares_with<I, collections::size_of_t<P>, &stdex::is_lt>)
42  return collections::get_element(std::forward<P>(p), i);
43  else if constexpr (values::size_compares_with<I, collections::size_of_t<P>, &stdex::is_gteq>)
44  return Dimensions<1>{};
46  return Any {collections::get_element(std::forward<P>(p) | collections::views::all, i)};
47  else
48  return Any {1_uz};
49  }
50 
51 
55 #ifdef __cpp_concepts
56  template<std::size_t i, pattern_collection P>
57  constexpr pattern decltype(auto)
58 #else
59  template<std::size_t i, typename P, std::enable_if_t<pattern_collection<P>, int> = 0>
60  constexpr decltype(auto)
61 #endif
62  get_pattern(P&& p)
63  {
64  return get_pattern(std::forward<P>(p), std::integral_constant<std::size_t, i>{});
65  }
66 
67 
68 }
69 
70 
71 #endif
Definition for pattern_collection.
constexpr auto get_size(Arg &&arg)
Get the size of a sized object (e.g, a collection)
Definition: get_size.hpp:224
decltype(auto) constexpr get_pattern(P &&p, I i)
Get a pattern within a pattern_collection.
Definition: get_pattern.hpp:39
constexpr bool pattern
An object describing the characteristics (e.g., dimensions, wrapping structure) of an index...
Definition: pattern.hpp:31
Definition of the Dimensions class.
decltype(auto) constexpr to_value_type(Arg &&arg)
Convert, if necessary, a fixed or dynamic value to its underlying base type.
Definition: to_value_type.hpp:28
A structure representing the dimensions associated with of a particular index.
Definition: Dimensions.hpp:42
Definition for patterns::pattern.
The namespace for features relating to patterns::pattern object.
Definition: collection_compares_with.hpp:24
constexpr detail::all_closure all
a std::ranges::range_adaptor_closure which returns a view to all members of its collection argument...
Definition: all.hpp:70
std::conditional_t< sized< T >, size_of< T >, values::unbounded_size_t > size_of_t
The type of the argument&#39;s size, which will satisfy values::size.
Definition: size_of.hpp:69
Inclusion file for collections.
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
decltype(auto) constexpr get_element(Arg &&arg, I i)
A generalization of std::get and the range subscript operator.
Definition: get_element.hpp:124
Definition: Any.hpp:42