OpenKalman
attach_patterns.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-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_MAKE_ATTACH_PATTERNS_HPP
17 #define OPENKALMAN_MAKE_ATTACH_PATTERNS_HPP
18 
19 #include "patterns/patterns.hpp"
23 
24 namespace OpenKalman
25 {
26  namespace detail
27  {
32  template <typename T>
33  struct is_pattern_adapter : std::false_type {};
34 
35  template <typename N, typename P>
36  struct is_pattern_adapter<pattern_adapter<N, P>> : std::true_type {};
37 
42  template<typename T>
43  constexpr auto is_pattern_adapter_v = is_pattern_adapter<T>::value;
44 
45  }
46 
47 
51  template<typename Arg>
52  constexpr decltype(auto)
53  detach_patterns(Arg&& arg)
54  {
55  if constexpr (detail::is_pattern_adapter<std::decay_t<Arg>>::value)
56  return std::forward<Arg>(arg).nested_object();
57  else
58  return std::forward<Arg>(arg);
59  }
60 
61 
67 #ifdef __cpp_concepts
68  template<indexible Arg, pattern_collection_for<Arg> P>
69 #else
70  template<typename Arg, typename P, std::enable_if_t<
71  indexible<Arg> and pattern_collection_for<P, Arg>, int> = 0>
72 #endif
73  constexpr decltype(auto)
74  attach_patterns(Arg&& arg, P&& p)
75  {
76  if constexpr (patterns::euclidean_pattern_collection<P>)
77  return detach_patterns(std::forward<Arg>(arg));
78  else
79  return pattern_adapter {detach_patterns(std::forward<Arg>(arg)), std::forward<P>(p)};
80  }
81 
82 }
83 
84 #endif
Definition: attach_patterns.hpp:33
decltype(auto) constexpr attach_patterns(Arg &&arg, P &&p)
Attach a pattern_collection to an indexible object.
Definition: attach_patterns.hpp:74
constexpr bool value
T is a fixed or dynamic value that is reducible to a number.
Definition: value.hpp:45
decltype(auto) constexpr detach_patterns(Arg &&arg)
If the argument is a pattern_adapter, detach the patterns::pattern_collection.
Definition: attach_patterns.hpp:53
The root namespace for OpenKalman.
Definition: basics.hpp:34
Definition for pattern_adapter.
An adapter that attaches a pattern_collection to an indexible object.
Definition: pattern_adapter.hpp:38
Definition for pattern_collection_for.
Definition for indexible.