Automatic Differentiation
 
Loading...
Searching...
No Matches
forward_as.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_META_FORWARD_AS_HPP
2#define STAN_MATH_PRIM_META_FORWARD_AS_HPP
3
5#include <type_traits>
6
7namespace stan {
8namespace math {
9
10namespace internal {
11template <typename T1, typename T2>
12constexpr bool eigen_static_size_match(T1 desired, T2 actual) {
13 return static_cast<int>(desired) == Eigen::Dynamic
14 || static_cast<int>(desired) == static_cast<int>(actual);
15}
16} // namespace internal
17
32template <typename T_desired, typename T_actual,
33 typename
34 = std::enable_if_t<std::is_same<std::decay_t<T_actual>,
35 std::decay_t<T_desired>>::value
37inline T_actual&& forward_as(T_actual&& a) { // NOLINT
38 return std::forward<T_actual>(a);
39}
40
57template <typename T_desired, typename T_actual,
58 typename = std::enable_if_t<
59 !std::is_same<std::decay<T_actual>, std::decay<T_desired>>::value
61inline T_desired forward_as(const T_actual& a) {
62 throw std::runtime_error("Wrong type assumed! Please file a bug report.");
63}
64
79template <
80 typename T_desired, typename T_actual,
82 std::enable_if_t<
83 std::is_same<value_type_t<T_actual>, value_type_t<T_desired>>::value
86 T_desired::RowsAtCompileTime,
87 std::decay_t<T_actual>::RowsAtCompileTime)
89 T_desired::ColsAtCompileTime,
90 std::decay_t<T_actual>::ColsAtCompileTime)>* = nullptr>
91inline T_actual&& forward_as(T_actual&& a) { // NOLINT
92 return std::forward<T_actual>(a);
93}
94
111template <
112 typename T_desired, typename T_actual,
114 std::enable_if_t<
115 !std::is_same<value_type_t<T_actual>, value_type_t<T_desired>>::value
117 T_desired::RowsAtCompileTime,
118 std::decay_t<T_actual>::RowsAtCompileTime)
120 T_desired::ColsAtCompileTime,
121 std::decay_t<T_actual>::ColsAtCompileTime)>* = nullptr>
122inline T_desired forward_as(const T_actual& a) {
123 throw std::runtime_error("Wrong type assumed! Please file a bug report.");
124}
125
126} // namespace math
127} // namespace stan
128#endif
require_all_t< is_eigen< std::decay_t< Types > >... > require_all_eigen_t
Require all of the types satisfy is_eigen.
Definition is_eigen.hpp:65
require_t< is_eigen< std::decay_t< T > > > require_eigen_t
Require type satisfies is_eigen.
Definition is_eigen.hpp:55
typename value_type< T >::type value_type_t
Helper function for accessing underlying type.
T_actual && forward_as(T_actual &&a)
Assume which type we get.
constexpr bool eigen_static_size_match(T1 desired, T2 actual)
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Check if type derives from EigenBase
Definition is_eigen.hpp:21