Loading [MathJax]/extensions/TeX/AMSsymbols.js
Automatic Differentiation
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
to_ref.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_TO_REF_HPP
2#define STAN_MATH_PRIM_FUN_TO_REF_HPP
3
6
7namespace stan {
8namespace math {
9
17template <typename T, require_not_tuple_t<T>* = nullptr>
18inline ref_type_t<T&&> to_ref(T&& a) {
19 return std::forward<T>(a);
20}
21
28template <typename T, require_tuple_t<T>* = nullptr>
29inline auto to_ref(T&& a) {
30 return apply(
31 [](auto&&... args) {
32 return make_holder_tuple(to_ref(std::forward<decltype(args)>(args))...);
33 },
34 std::forward<T>(a));
35}
36
44template <bool Cond, typename T, std::enable_if_t<!Cond>* = nullptr>
45inline T to_ref_if(T&& a) {
46 return std::forward<T>(a);
47}
48
58template <bool Cond, typename T, std::enable_if_t<Cond>* = nullptr>
60 return std::forward<T>(a);
61}
62
63} // namespace math
64} // namespace stan
65#endif
T to_ref_if(T &&a)
No-op that should be optimized away.
Definition to_ref.hpp:45
constexpr auto make_holder_tuple(Types &&... args)
Holds ownership of rvalues and forwards lvalues into a tuple.
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
Definition to_ref.hpp:18
constexpr decltype(auto) apply(F &&f, Tuple &&t, PreArgs &&... pre_args)
Definition apply.hpp:51
typename ref_type_if< true, T >::type ref_type_t
Definition ref_type.hpp:55
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...