1 #ifndef STAN_MATH_PRIM_FUN_SORT_ASC_HPP
2 #define STAN_MATH_PRIM_FUN_SORT_ASC_HPP
3 
4 #include <stan/math/prim/meta.hpp>
5 #include <stan/math/prim/err.hpp>
6 #include <stan/math/prim/fun/Eigen.hpp>
7 #include <algorithm>
8 #include <vector>
9 
10 namespace stan {
11 namespace math {
12 
13 /**
14  * Return the specified standard vector in ascending order.
15  *
16  * @tparam T Type of elements contained in vector.
17  * @param xs Vector to order.
18  * @return Vector in ascending order.
19  * @throw std::domain_error If any of the values are NaN.
20  */
21 template <typename T>
sort_asc(std::vector<T> xs)22 inline std::vector<T> sort_asc(std::vector<T> xs) {
23   check_not_nan("sort_asc", "container argument", xs);
24   std::sort(xs.begin(), xs.end());
25   return xs;
26 }
27 
28 /**
29  * Return the specified vector in ascending order.
30  *
31  * @tparam EigVec type of the vector
32  *
33  * @param xs Vector to order.
34  * @return Vector in ascending order.
35  * @throw std::domain_error If any of the values are NaN.
36  */
37 template <typename EigVec, require_eigen_vector_t<EigVec>* = nullptr>
sort_asc(EigVec && xs)38 inline plain_type_t<EigVec> sort_asc(EigVec&& xs) {
39   plain_type_t<EigVec> x = std::forward<EigVec>(xs);
40   check_not_nan("sort_asc", "container argument", x);
41   std::sort(x.data(), x.data() + x.size());
42   return x;
43 }
44 
45 }  // namespace math
46 }  // namespace stan
47 
48 #endif
49