1 #ifndef STAN_MATH_PRIM_FUN_EVAL_HPP
2 #define STAN_MATH_PRIM_FUN_EVAL_HPP
3 
4 #include <stan/math/prim/meta.hpp>
5 #include <stan/math/prim/fun/Eigen.hpp>
6 
7 namespace stan {
8 namespace math {
9 
10 /**
11  * Inputs which have a plain_type equal to the own time are forwarded
12  * unmodified (for Eigen expressions these types are different)
13  *
14  * @tparam T Input type
15  * @param[in] arg Input argument
16  * @return Forwarded input argument
17  **/
18 template <typename T,
19           require_same_t<std::decay_t<T>, plain_type_t<T>>* = nullptr>
eval(T && arg)20 inline T eval(T&& arg) {
21   return std::forward<T>(arg);
22 }
23 
24 /**
25  * Inputs which have a plain_type different from their own type are
26  * Eval'd (this catches Eigen expressions)
27  *
28  * @tparam T Input type
29  * @param[in] arg Input argument
30  * @return Eval'd argument
31  **/
32 template <typename T,
33           require_not_same_t<std::decay_t<T>, plain_type_t<T>>* = nullptr>
eval(const T & arg)34 inline decltype(auto) eval(const T& arg) {
35   return arg.eval();
36 }
37 
38 }  // namespace math
39 }  // namespace stan
40 
41 #endif
42