1 #ifndef STAN_MATH_PRIM_ARR_FUN_PROMOTE_ELEMENTS_HPP
2 #define STAN_MATH_PRIM_ARR_FUN_PROMOTE_ELEMENTS_HPP
3 
4 #include <stan/math/prim/scal/fun/promote_elements.hpp>
5 #include <vector>
6 #include <cstddef>
7 
8 namespace stan {
9 namespace math {
10 
11 /**
12  * Struct with static function for elementwise type promotion.
13  *
14  * <p>This specialization promotes vector elements of different types
15  * which must be compatible with promotion.
16  *
17  * @tparam T type of promoted elements
18  * @tparam S type of input elements, must be assignable to T
19  */
20 template <typename T, typename S>
21 struct promote_elements<std::vector<T>, std::vector<S> > {
22   /**
23    * Return input vector of type S as vector of type T.
24    *
25    * @param u vector of type S, assignable to type T
26    * @returns vector of type T
27    */
promotestan::math::promote_elements28   inline static std::vector<T> promote(const std::vector<S>& u) {
29     std::vector<T> t;
30     t.reserve(u.size());
31     for (size_t i = 0; i < u.size(); ++i)
32       t.push_back(promote_elements<T, S>::promote(u[i]));
33     return t;
34   }
35 };
36 
37 /**
38  * Struct with static function for elementwise type promotion.
39  *
40  * <p>This specialization promotes vector elements of the same type.
41  *
42  * @tparam T type of elements
43  */
44 template <typename T>
45 struct promote_elements<std::vector<T>, std::vector<T> > {
46   /**
47    * Return input vector.
48    *
49    * @param u vector of type T
50    * @returns vector of type T
51    */
promotestan::math::promote_elements52   inline static const std::vector<T>& promote(const std::vector<T>& u) {
53     return u;
54   }
55 };
56 
57 }  // namespace math
58 }  // namespace stan
59 
60 #endif
61