OpenKalman
AdapterBase.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) 2019-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 
17 #ifndef OPENKALMAN_ADAPTERBASE_HPP
18 #define OPENKALMAN_ADAPTERBASE_HPP
19 
20 #include "linear-algebra/traits/internal/library_base.hpp"
21 
22 namespace OpenKalman::internal
23 {
31 #ifdef __cpp_concepts
32  template<typename Derived, indexible Nested, indexible LibraryObject = Nested> requires
33  (not std::is_rvalue_reference_v<Nested>)
34 #else
35  template<typename Derived, typename Nested, typename LibraryObject = Nested>
36 #endif
37  struct AdapterBase : library_base_t<Derived, LibraryObject>
38  {
39 
40 #ifndef __cpp_concepts
41  static_assert(indexible<Nested>);
42  static_assert(indexible<LibraryObject>);
43  static_assert(not std::is_rvalue_reference_v<Nested>);
44 #endif
45 
49  constexpr
50  AdapterBase() = default;
51 
52 
56 #ifdef __cpp_concepts
57  template<typename Arg> requires
58  (not std::is_base_of_v<Derived, std::decay_t<Arg>>) and
59  std::constructible_from<Nested, Arg&&>
60 #else
61  template<typename Arg, std::enable_if_t<
62  (not std::is_base_of_v<Derived, std::decay_t<Arg>>) and
63  stdex::constructible_from<Nested, Arg&&>, int> = 0>
64 #endif
65  constexpr explicit
66  AdapterBase(Arg&& arg) : nested_ {std::forward<Arg>(arg)} {}
67 
68 
72 #ifdef __cpp_explicit_this_parameter
73  template<typename Self>
74  constexpr decltype(auto) nested_object(this Self&& self) { return std::forward<Self>(self).nested_; }
75 #else
76  constexpr Nested& nested_object() & { return nested_; }
77 
79  constexpr const Nested& nested_object() const & { return nested_; }
80 
82  constexpr Nested&& nested_object() && { return std::move(*this).nested_; }
83 
85  constexpr const Nested&& nested_object() const && { return std::move(*this).nested_; }
86 #endif
87 
88  private:
89 
90  Nested nested_;
91 
92  };
93 
94 }
95 
96 #endif
Definition: AdapterBase.hpp:37
constexpr AdapterBase()=default
Default constructor.
constexpr Nested & nested_object() &
Get the nested object.
Definition: AdapterBase.hpp:76
constexpr const Nested && nested_object() const &&
Definition: AdapterBase.hpp:85
constexpr AdapterBase(Arg &&arg)
Construct from the nested type.
Definition: AdapterBase.hpp:66
constexpr Nested && nested_object() &&
Definition: AdapterBase.hpp:82
Definition: basics.hpp:48
constexpr const Nested & nested_object() const &
Definition: AdapterBase.hpp:79