Skip to content

Commit

Permalink
Merge pull request #2874 from andrjohns/additional-cpp17-compat
Browse files Browse the repository at this point in the history
Use unambiguous size function with old rstan
  • Loading branch information
hsbadr authored Feb 24, 2023
2 parents 4d7b4a2 + cdcd803 commit 04b0ef4
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions stan/math/prim/fun/size.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ inline size_t size(const T& /*x*/) {
return 1U;
}

#ifdef USE_STANC3

/** \ingroup type_trait
* Returns the size of the provided Eigen matrix, expression or std::vector.
*
Expand All @@ -29,11 +31,39 @@ inline size_t size(const T& m) {
return m.size();
}

#else

/** \ingroup type_trait
* Returns the size of the provided Eigen matrix, expression or std::vector.
*
* @param m input \c Eigen \c Matrix, expression or std::vector
* @tparam T type of m
*/
template <typename T, require_eigen_t<T>* = nullptr>
inline size_t size(const T& m) {
return m.size();
}

/**
* Return the size of the specified standard vector.
*
* @tparam T Type of elements.
* @param[in] x Input vector.
* @return Size of input vector.
*/
template <typename T>
inline size_t size(const std::vector<T>& x) {
return x.size();
}

#endif

template <typename T, require_var_matrix_t<T>* = nullptr>
inline size_t size(const T& m) {
return m.size();
}


} // namespace math
} // namespace stan
#endif

0 comments on commit 04b0ef4

Please sign in to comment.