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
7#include <vector>
8
9namespace stan {
10namespace math {
11
24template <typename T>
26 private:
28
29 public:
35 template <typename S,
37 explicit chainable_object(S&& obj) : obj_(std::forward<S>(obj)) {}
38
44 inline auto& get() noexcept { return obj_; }
45 inline const auto& get() const noexcept { return obj_; }
46};
47
57template <typename T>
58auto make_chainable_ptr(T&& obj) {
59 auto ptr = new chainable_object<T>(std::forward<T>(obj));
60 return &ptr->get();
61}
62
77template <typename T>
79 private:
80 std::decay_t<T> obj_;
81
82 public:
88 template <typename S,
90 explicit unsafe_chainable_object(S&& obj) : obj_(std::forward<S>(obj)) {}
91
97 inline auto& get() noexcept { return obj_; }
98 inline const auto& get() const noexcept { return obj_; }
99};
100
112template <typename T>
114 auto ptr = new unsafe_chainable_object<T>(std::forward<T>(obj));
115 return &ptr->get();
116}
117
118} // namespace math
119} // namespace stan
120#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 ...
STL namespace.