OpenKalman
attach_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) 2023-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_MAKE_ATTACH_PATTERN_HPP
17 #define OPENKALMAN_MAKE_ATTACH_PATTERN_HPP
18 
19 #include "coordinates/coordinates.hpp"
22 #include "linear-algebra/adapters/pattern_adapter.hpp"
23 
24 namespace OpenKalman
25 {
30 #ifdef __cpp_concepts
31  template<indexible Arg, pattern_collection_for<Arg> P>
32 #else
33  template<typename Arg, typename P, std::enable_if_t<
34  indexible<Arg> and pattern_collection_for<P, Arg>, int> = 0>
35 #endif
36  constexpr auto attach_pattern(Arg&& arg, P&& p)
37  {
38  if constexpr (coordinates::euclidean_pattern_collection<P>)
39  return std::forward<Arg>(arg);
40  else
41  return pattern_adapter{std::forward<Arg>(arg), std::forward<P>(p)};
42  }
43 
44 
49 #ifdef __cpp_concepts
50  template<indexible Arg, coordinates::pattern...Ps> requires pattern_collection_for<std::tuple<Ps...>, Arg>
51 #else
52  template<typename Arg, typename...Ps, std::enable_if_t<
53  indexible<Arg> and (... and coordinates::pattern<Ps>) and
54  pattern_collection_for<std::tuple<Ps...>, Arg>, int> = 0>
55 #endif
56  constexpr auto attach_pattern(Arg&& arg, Ps&&...ps)
57  {
58  return attach_pattern(std::forward<Arg>(arg), std::tuple {std::forward<Ps>(ps)...});
59  }
60 
61 
66 #ifdef __cpp_concepts
67  template<coordinates::pattern_collection P, indexible Arg> requires
68  pattern_collection_for<P, Arg> and
69  std::default_initializable<P>
70 #else
71  template<typename P, typename Arg, std::enable_if_t<
72  indexible<Arg> and
73  pattern_collection_for<P, Arg>, int> = 0>
74 #endif
75  constexpr auto attach_pattern(Arg&& arg)
76  {
77  return attach_pattern(std::forward<Arg>(arg), P{});
78  }
79 
80 
81 }
82 
83 #endif
constexpr auto attach_pattern(Arg &&arg, P &&p)
Attach a pattern_collection to an indexible object.
Definition: attach_pattern.hpp:36
constexpr bool pattern
An object describing the set of coordinates associated with a tensor index.
Definition: pattern.hpp:31
constexpr bool indexible
T is a multidimensional array type.
Definition: indexible.hpp:32
The root namespace for OpenKalman.
Definition: basics.hpp:34
An adapter that attaches a pattern_collection to an indexible object.
Definition: pattern_adapter.hpp:35
Definition for pattern_collection_for.
Definition for indexible.
constexpr bool pattern_collection_for
pattern collection P is compatible with indexible T.
Definition: pattern_collection_for.hpp:66