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 #include "basics/basics.hpp"
20 
21 namespace OpenKalman::internal
22 {
23 #ifdef __cpp_concepts
24  template<indexible NestedObject, pattern_collection Descriptors> requires
25  compatible_with_vector_space_descriptor_collection<NestedObject, Descriptors> and
26  internal::not_more_fixed_than<NestedObject, Descriptors> and internal::less_fixed_than<NestedObject, Descriptors>
27 #else
28  template<typename NestedObject, typename Descriptors>
29 #endif
30  struct FixedSizeAdapter : AdapterBase<FixedSizeAdapter<NestedObject, Descriptors>, const NestedObject>
31  {
32  private:
33 
34 #ifndef __cpp_concepts
35  static_assert(indexible<NestedObject>);
36  static_assert(pattern_collection<Descriptors>);
37  static_assert(compatible_with_vector_space_descriptor_collection<NestedObject, Descriptors>);
38  static_assert(internal::not_more_fixed_than<NestedObject, Descriptors>);
39  static_assert(internal::less_fixed_than<NestedObject, Descriptors>);
40 #endif
41 
43 
44  public:
45 
46  using Base::Base;
47 
48 
54 #ifdef __cpp_concepts
55  template<compatible_with_vector_space_descriptor_collection<Descriptors> Arg> requires
56  std::constructible_from<NestedObject, Arg&&> and (not fixed_size_adapter<Arg>)
57 #else
58  template<typename Arg, std::enable_if_t<
59  compatible_with_vector_space_descriptors<Arg, Descriptors> and stdex::constructible_from<NestedObject, Arg&&> and
60  (not fixed_size_adapter<Arg>), int> = 0>
61 #endif
62  constexpr FixedSizeAdapter(Arg&& arg, const Descriptors&) : Base {std::forward<Arg>(arg)} {}
63 
64 
70 #ifdef __cpp_concepts
71  template<compatible_with_vector_space_descriptor_collection<Descriptors> Arg, coordinates::pattern...Ds> requires
72  (sizeof...(Ds) == 0 or std::same_as<std::tuple<Ds...>, Descriptors>) and
73  std::constructible_from<NestedObject, Arg&&> and (not fixed_size_adapter<Arg>)
74 #else
75  template<typename Arg, typename...Ds, std::enable_if_t<
76  compatible_with_vector_space_descriptors<Arg, Vs...> and (... and coordinates::pattern<Ds>) and
77  std::is_same_v<std::tuple<Ds...>, Descriptors> and
78  stdex::constructible_from<NestedObject, Arg&&> and (not fixed_size_adapter<Arg>), int> = 0>
79 #endif
80  constexpr FixedSizeAdapter(Arg&& arg, const Ds&...) : Base {std::forward<Arg>(arg)} {}
81 
82 
87 #ifdef __cpp_concepts
88  template<compatible_with_vector_space_descriptor_collection<Descriptors> Arg> requires
89  std::constructible_from<NestedObject, nested_object_of_t<Arg&&>> and fixed_size_adapter<Arg>
90 #else
91  template<typename Arg, std::enable_if_t<
92  compatible_with_vector_space_descriptors<Arg, Descriptors> and
93  stdex::constructible_from<NestedObject, nested_object_of_t<Arg&&>> and fixed_size_adapter<Arg>, int> = 0>
94 #endif
95  constexpr FixedSizeAdapter(Arg&& arg, const Descriptors&...) : Base {nested_object(std::forward<Arg>(arg))} {}
96 
97 
105 #ifdef __cpp_concepts
106  template<compatible_with_vector_space_descriptor_collection<Descriptors> Arg, coordinates::pattern...Ds> requires
107  (sizeof...(Ds) == 0 or std::same_as<std::tuple<Ds...>, Descriptors>) and
108  std::constructible_from<NestedObject, nested_object_of_t<Arg&&>> and fixed_size_adapter<Arg>
109 #else
110  template<typename Arg, typename...Ds, std::enable_if_t<
111  compatible_with_vector_space_descriptors<Arg, Vs...> and (... and coordinates::pattern<Ds>) and
112  std::is_same_v<std::tuple<Ds...>, Descriptors> and
113  stdex::constructible_from<NestedObject, nested_object_of_t<Arg&&>> and fixed_size_adapter<Arg>, int> = 0>
114 #endif
115  constexpr FixedSizeAdapter(Arg&& arg, const Ds&...) : Base {nested_object(std::forward<Arg>(arg))} {}
116 
117 
121 #ifdef __cpp_concepts
122  template<compatible_with_vector_space_descriptor_collection<Descriptors> Arg> requires
123  std::assignable_from<std::add_lvalue_reference_t<NestedObject>, Arg&&>
124 #else
125  template<typename Arg, std::enable_if_t<compatible_with_vector_space_descriptor_collection<Arg, Descriptors> and
126  std::is_assignable_v<std::add_lvalue_reference_t<NestedObject>, Arg&&>, int> = 0>
127 #endif
128  constexpr FixedSizeAdapter& operator=(Arg&& arg)
129  {
130  Base::operator=(std::forward<Arg>(arg));
131  return *this;
132  }
133 
134 
138  constexpr decltype(auto) nested_object() const & { return Base::nested_object(); }
139 
141  constexpr decltype(auto) nested_object() const && { return std::move(static_cast<const Base&&>(*this)).nested_object(); }
142 
143  };
144 
145 
146  // ------------------ //
147  // Deduction Guides //
148  // ------------------ //
149 
150 #ifdef __cpp_concepts
151  template<indexible Arg, pattern_collection Descriptors> requires (not fixed_size_adapter<Arg>)
152 #else
153  template<typename Arg, typename...Vs, std::enable_if_t<indexible<Arg> and pattern_collection<Descriptors> and
154  (not fixed_size_adapter<Arg>), int> = 0>
155 #endif
156  FixedSizeAdapter(Arg&&, const Descriptors&) -> FixedSizeAdapter<Arg, Descriptors>;
157 
158 
159 #ifdef __cpp_concepts
160  template<indexible Arg, coordinates::pattern...Vs> requires (not fixed_size_adapter<Arg>)
161 #else
162  template<typename Arg, typename...Vs, std::enable_if_t<indexible<Arg> and (... and coordinates::pattern<Vs>) and
163  (not fixed_size_adapter<Arg>), int> = 0>
164 #endif
165  FixedSizeAdapter(Arg&&, const Vs&...) -> FixedSizeAdapter<Arg, std::tuple<Vs...>>;
166 
167 
168 #ifdef __cpp_concepts
169  template<fixed_size_adapter Arg, pattern_collection Descriptors>
170 #else
171  template<typename Arg, typename Descriptors, std::enable_if_t<fixed_size_adapter<Arg> and pattern_collection<Descriptors>, int> = 0>
172 #endif
173  FixedSizeAdapter(Arg&&, const Descriptors&) ->
175 
176 
177 #ifdef __cpp_concepts
178  template<fixed_size_adapter Arg, coordinates::pattern...Vs>
179 #else
180  template<typename Arg, typename...Vs, std::enable_if_t<
181  fixed_size_adapter<Arg> and (... and coordinates::pattern<Vs>), int> = 0>
182 #endif
183  FixedSizeAdapter(Arg&&, const Vs&...) ->
185 
186 
187 }
188 
189 
190 #endif
decltype(auto) constexpr nested_object() const &
Get the nested object.
Definition: FixedSizeAdapter.hpp:138
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
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:95
Definition: AdapterBase.hpp:37
constexpr FixedSizeAdapter(Arg &&arg, const Descriptors &)
Construct from a compatible indexible object.
Definition: FixedSizeAdapter.hpp:62
constexpr FixedSizeAdapter & operator=(Arg &&arg)
Assign from another compatible indexible object.
Definition: FixedSizeAdapter.hpp:128
Definition: FixedSizeAdapter.hpp:30
constexpr Nested & nested_object() &
Get the nested object.
Definition: AdapterBase.hpp:76
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:80
Basic definitions for OpenKalman as a whole.
Definition: basics.hpp:48