OpenKalman
LibraryWrapper.hpp
1 /* This file is part of OpenKalman, a header-only C++ library for
2  * Kalman filters and other recursive filters.
3  *
4  * Copyright (c) 2022-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 
17 #ifndef OPENKALMAN_LIBRARYWRAPPER_HPP
18 #define OPENKALMAN_LIBRARYWRAPPER_HPP
19 
20 
21 namespace OpenKalman::internal
22 {
23 
24 #ifdef __cpp_concepts
25  template<indexible NestedObject, indexible LibraryObject>
26 #else
27  template<typename NestedObject, typename LibraryObject>
28 #endif
29  struct LibraryWrapper : AdapterBase<LibraryWrapper<NestedObject, LibraryObject>, NestedObject, LibraryObject>
30  {
31  private:
32 
33  using Base = AdapterBase<LibraryWrapper, NestedObject, LibraryObject>;
34 
35  public:
36 
37  using Base::Base;
38 
39 
43 #ifdef __cpp_concepts
44  template<indexible Arg> requires
45  (std::assignable_from<std::add_lvalue_reference_t<NestedObject>, Arg&&> or
46  std::assignable_from<std::add_lvalue_reference_t<NestedObject>, decltype(to_native_matrix<NestedObject>(std::declval<Arg&&>()))>)
47 #else
48  template<typename Arg, std::enable_if_t<
49  (std::is_assignable_v<std::add_lvalue_reference_t<NestedObject>, Arg&&> or
50  std::is_assignable_v<std::add_lvalue_reference_t<NestedObject>, decltype(to_native_matrix<NestedObject>(std::declval<Arg&&>()))>), int> = 0>
51 #endif
52  constexpr LibraryWrapper& operator=(Arg&& arg)
53  {
54 #ifdef __cpp_concepts
55  if constexpr (std::assignable_from<std::add_lvalue_reference_t<NestedObject>, Arg&&>)
56 #else
57  if constexpr (std::is_assignable_v<std::add_lvalue_reference_t<NestedObject>, Arg&&>)
58 #endif
59  Base::operator=(std::forward<Arg>(arg));
60  else
61  Base::operator=(to_native_matrix<NestedObject>(std::forward<Arg>(arg)));
62  return *this;
63  }
64 
65 
69  constexpr operator NestedObject& () & { return this->nested_object(); }
70 
72  constexpr operator const NestedObject& () const & { return this->nested_object(); }
73 
75  constexpr operator NestedObject&& () && { return std::move(*this).nested_object(); }
76 
78  constexpr operator const NestedObject&& () const && { return std::move(*this).nested_object(); }
79 
80  };
81 
82 
83 } // namespace OpenKalman::internal
84 
85 
86 #endif //OPENKALMAN_LIBRARYWRAPPER_HPP
constexpr NestedObject & nested_object() &
Get the nested object.
Definition: AdapterBase.hpp:97
constexpr AdapterBase & operator=(Arg &&arg)
Assign from another compatible indexible object.
Definition: AdapterBase.hpp:82
Definition: forward-class-declarations.hpp:580
Definition: basics.hpp:48