Automatic Differentiation
 
Loading...
Searching...
No Matches
chainable_object.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_REV_CORE_CHAINABLE_OBJECT_HPP
2#define STAN_MATH_REV_CORE_CHAINABLE_OBJECT_HPP
3
9#include <vector>
10
11namespace stan {
12namespace math {
13
26template <typename T>
28 private:
30
31 public:
37 template <typename S,
39 explicit chainable_object(S&& obj) : obj_(std::forward<S>(obj)) {}
40
46 inline auto& get() noexcept { return obj_; }
47 inline const auto& get() const noexcept { return obj_; }
48};
49
59template <typename T>
60auto make_chainable_ptr(T&& obj) {
61 auto ptr = new chainable_object<T>(std::forward<T>(obj));
62 return &ptr->get();
63}
64
79template <typename T>
81 private:
82 std::decay_t<T> obj_;
83
84 public:
90 template <typename S,
92 explicit unsafe_chainable_object(S&& obj) : obj_(std::forward<S>(obj)) {}
93
99 inline auto& get() noexcept { return obj_; }
100 inline const auto& get() const noexcept { return obj_; }
101};
102
114template <typename T>
116 auto ptr = new unsafe_chainable_object<T>(std::forward<T>(obj));
117 return &ptr->get();
118}
119
120} // namespace math
121} // namespace stan
122#endif
A chainable_alloc is an object which is constructed and destructed normally but the memory lifespan i...
const auto & get() const noexcept
auto & get() noexcept
Return a reference to the underlying object.
chainable_object(S &&obj)
Construct chainable object from another object.
chainable_object hold another object is useful for connecting the lifetime of a specific object to th...
unsafe_chainable_object(S &&obj)
Construct chainable object from another object.
auto & get() noexcept
Return a reference to the underlying object.
const auto & get() const noexcept
unsafe_chainable_object hold another object and is useful for connecting the lifetime of a specific o...
require_t< std::is_same< std::decay_t< T >, std::decay_t< S > > > require_same_t
Require types T and S satisfies std::is_same.
auto make_unsafe_chainable_ptr(T &&obj)
Store the given object in a chainable_object so it is destructed only when the chainable stack memory...
auto make_chainable_ptr(T &&obj)
Store the given object in a chainable_object so it is destructed only when the chainable stack memory...
typename plain_type< T >::type plain_type_t
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Definition fvar.hpp:9
STL namespace.