1 #ifndef STAN_MATH_PRIM_FUN_IF_ELSE_HPP
2 #define STAN_MATH_PRIM_FUN_IF_ELSE_HPP
3 
4 #include <stan/math/prim/meta.hpp>
5 
6 namespace stan {
7 namespace math {
8 
9 /**
10  * Return the second argument if the first argument is true
11  * and otherwise return the second argument.
12  *
13  * <p>This is just a convenience method to provide a function
14  * with the same behavior as the built-in ternary operator.
15  * In general, this function behaves as if defined by
16  *
17  * <p><code>if_else(c, y1, y0) = c ? y1 : y0</code>.
18  *
19  * @tparam T_true type of the true argument
20  * @tparam T_false type of the false argument
21  * @param c Boolean condition value.
22  * @param y_true Value to return if condition is true.
23  * @param y_false Value to return if condition is false.
24  */
25 template <typename T_true, typename T_false>
if_else(const bool c,const T_true y_true,const T_false y_false)26 inline return_type_t<T_true, T_false> if_else(const bool c, const T_true y_true,
27                                               const T_false y_false) {
28   return c ? y_true : y_false;
29 }
30 
31 }  // namespace math
32 }  // namespace stan
33 
34 #endif
35