OpenKalman
FixedSizeAdapter.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-2024 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_FIXEDSIZEADAPTER_HPP
17 #define OPENKALMAN_FIXEDSIZEADAPTER_HPP
18 
19 namespace OpenKalman::internal
20 {
21 #ifdef __cpp_concepts
22  template<indexible NestedObject, pattern_tuple Descriptors> requires
23  compatible_with_vector_space_descriptor_collection<NestedObject, Descriptors> and
24  internal::not_more_fixed_than<NestedObject, Descriptors> and internal::less_fixed_than<NestedObject, Descriptors>
25 #else
26  template<typename NestedObject, typename Descriptors>
27 #endif
28  struct FixedSizeAdapter : AdapterBase<FixedSizeAdapter<NestedObject, Descriptors>, const NestedObject>
29  {
30  private:
31 
32 #ifndef __cpp_concepts
33  static_assert(indexible<NestedObject>);
34  static_assert(pattern_tuple<Descriptors>);
35  static_assert(compatible_with_vector_space_descriptor_collection<NestedObject, Descriptors>);
36  static_assert(internal::not_more_fixed_than<NestedObject, Descriptors>);
37  static_assert(internal::less_fixed_than<NestedObject, Descriptors>);
38 #endif
39 
41 
42  public:
43 
44  using Base::Base;
45 
46 
52 #ifdef __cpp_concepts
53  template<compatible_with_vector_space_descriptor_collection<Descriptors> Arg> requires
54  std::constructible_from<NestedObject, Arg&&> and (not fixed_size_adapter<Arg>)
55 #else
56  template<typename Arg, std::enable_if_t<
57  compatible_with_vector_space_descriptors<Arg, Descriptors> and std::is_constructible_v<NestedObject, Arg&&> and
58  (not fixed_size_adapter<Arg>), int> = 0>
59 #endif
60  constexpr FixedSizeAdapter(Arg&& arg, const Descriptors&) : Base {std::forward<Arg>(arg)} {}
61 
62 
68 #ifdef __cpp_concepts
69  template<compatible_with_vector_space_descriptor_collection<Descriptors> Arg, coordinates::pattern...Ds> requires
70  (sizeof...(Ds) == 0 or std::same_as<std::tuple<Ds...>, Descriptors>) and
71  std::constructible_from<NestedObject, Arg&&> and (not fixed_size_adapter<Arg>)
72 #else
73  template<typename Arg, typename...Ds, std::enable_if_t<
74  compatible_with_vector_space_descriptors<Arg, Vs...> and (... and coordinates::pattern<Ds>) and
75  std::is_same_v<std::tuple<Ds...>, Descriptors> and
76  std::is_constructible_v<NestedObject, Arg&&> and (not fixed_size_adapter<Arg>), int> = 0>
77 #endif
78  constexpr FixedSizeAdapter(Arg&& arg, const Ds&...) : Base {std::forward<Arg>(arg)} {}
79 
80 
85 #ifdef __cpp_concepts
86  template<compatible_with_vector_space_descriptor_collection<Descriptors> Arg> requires
87  std::constructible_from<NestedObject, nested_object_of_t<Arg&&>> and fixed_size_adapter<Arg>
88 #else
89  template<typename Arg, std::enable_if_t<
90  compatible_with_vector_space_descriptors<Arg, Descriptors> and
91  std::is_constructible_v<NestedObject, nested_object_of_t<Arg&&>> and fixed_size_adapter<Arg>, int> = 0>
92 #endif
93  constexpr FixedSizeAdapter(Arg&& arg, const Descriptors&...) : Base {nested_object(std::forward<Arg>(arg))} {}
94 
95 
103 #ifdef __cpp_concepts
104  template<compatible_with_vector_space_descriptor_collection<Descriptors> Arg, coordinates::pattern...Ds> requires
105  (sizeof...(Ds) == 0 or std::same_as<std::tuple<Ds...>, Descriptors>) and
106  std::constructible_from<NestedObject, nested_object_of_t<Arg&&>> and fixed_size_adapter<Arg>
107 #else
108  template<typename Arg, typename...Ds, std::enable_if_t<
109  compatible_with_vector_space_descriptors<Arg, Vs...> and (... and coordinates::pattern<Ds>) and
110  std::is_same_v<std::tuple<Ds...>, Descriptors> and
111  std::is_constructible_v<NestedObject, nested_object_of_t<Arg&&>> and fixed_size_adapter<Arg>, int> = 0>
112 #endif
113  constexpr FixedSizeAdapter(Arg&& arg, const Ds&...) : Base {nested_object(std::forward<Arg>(arg))} {}
114 
115 
119 #ifdef __cpp_concepts
120  template<compatible_with_vector_space_descriptor_collection<Descriptors> Arg> requires
121  std::assignable_from<std::add_lvalue_reference_t<NestedObject>, Arg&&>
122 #else
123  template<typename Arg, std::enable_if_t<compatible_with_vector_space_descriptor_collection<Arg, Descriptors> and
124  std::is_assignable_v<std::add_lvalue_reference_t<NestedObject>, Arg&&>, int> = 0>
125 #endif
126  constexpr FixedSizeAdapter& operator=(Arg&& arg)
127  {
128  Base::operator=(std::forward<Arg>(arg));
129  return *this;
130  }
131 
132 
136  constexpr decltype(auto) nested_object() const & { return Base::nested_object(); }
137 
139  constexpr decltype(auto) nested_object() const && { return std::move(static_cast<const Base&&>(*this)).nested_object(); }
140 
141  };
142 
143 
144  // ------------------ //
145  // Deduction Guides //
146  // ------------------ //
147 
148 #ifdef __cpp_concepts
149  template<indexible Arg, pattern_collection Descriptors> requires (not fixed_size_adapter<Arg>)
150 #else
151  template<typename Arg, typename...Vs, std::enable_if_t<indexible<Arg> and pattern_collection<Descriptors> and
152  (not fixed_size_adapter<Arg>), int> = 0>
153 #endif
154  FixedSizeAdapter(Arg&&, const Descriptors&) -> FixedSizeAdapter<Arg, Descriptors>;
155 
156 
157 #ifdef __cpp_concepts
158  template<indexible Arg, coordinates::pattern...Vs> requires (not fixed_size_adapter<Arg>)
159 #else
160  template<typename Arg, typename...Vs, std::enable_if_t<indexible<Arg> and (... and coordinates::pattern<Vs>) and
161  (not fixed_size_adapter<Arg>), int> = 0>
162 #endif
163  FixedSizeAdapter(Arg&&, const Vs&...) -> FixedSizeAdapter<Arg, std::tuple<Vs...>>;
164 
165 
166 #ifdef __cpp_concepts
167  template<fixed_size_adapter Arg, pattern_collection Descriptors>
168 #else
169  template<typename Arg, typename Descriptors, std::enable_if_t<fixed_size_adapter<Arg> and pattern_collection<Descriptors>, int> = 0>
170 #endif
171  FixedSizeAdapter(Arg&&, const Descriptors&) ->
173 
174 
175 #ifdef __cpp_concepts
176  template<fixed_size_adapter Arg, coordinates::pattern...Vs>
177 #else
178  template<typename Arg, typename...Vs, std::enable_if_t<
179  fixed_size_adapter<Arg> and (... and coordinates::pattern<Vs>), int> = 0>
180 #endif
181  FixedSizeAdapter(Arg&&, const Vs&...) ->
183 
184 
185 } // namespace OpenKalman::internal
186 
187 
188 #endif //OPENKALMAN_FIXEDSIZEADAPTER_HPP
constexpr NestedObject & nested_object() &
Get the nested object.
Definition: AdapterBase.hpp:97
decltype(auto) constexpr nested_object() const &
Get the nested object.
Definition: FixedSizeAdapter.hpp:136
constexpr AdapterBase & operator=(Arg &&arg)
Assign from another compatible indexible object.
Definition: AdapterBase.hpp:82
constexpr bool indexible
T is a generalized tensor type.
Definition: indexible.hpp:32
constexpr FixedSizeAdapter(Arg &&arg, const Descriptors &...)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: FixedSizeAdapter.hpp:93
Definition: AdapterBase.hpp:36
constexpr FixedSizeAdapter(Arg &&arg, const Descriptors &)
Construct from a compatible indexible object.
Definition: FixedSizeAdapter.hpp:60
constexpr FixedSizeAdapter & operator=(Arg &&arg)
Assign from another compatible indexible object.
Definition: FixedSizeAdapter.hpp:126
Definition: FixedSizeAdapter.hpp:28
constexpr FixedSizeAdapter(Arg &&arg, const Ds &...)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: FixedSizeAdapter.hpp:78
Definition: basics.hpp:48