Stan Math Library  2.20.0
reverse mode automatic differentiation
check_std_vector_index.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_ERR_CHECK_STD_VECTOR_INDEX_HPP
2 #define STAN_MATH_PRIM_MAT_ERR_CHECK_STD_VECTOR_INDEX_HPP
3 
6 
7 #include <sstream>
8 #include <string>
9 #include <vector>
10 
11 namespace stan {
12 namespace math {
13 
25 template <typename T>
26 inline void check_std_vector_index(const char* function, const char* name,
27  const std::vector<T>& y, int i) {
28  if (i >= static_cast<int>(stan::error_index::value)
29  && i < static_cast<int>(y.size() + stan::error_index::value))
30  return;
31 
32  std::stringstream msg;
33  msg << " for " << name;
34  std::string msg_str(msg.str());
35  out_of_range(function, y.size(), i, msg_str.c_str());
36 }
37 
38 } // namespace math
39 } // namespace stan
40 #endif
void check_std_vector_index(const char *function, const char *name, const std::vector< T > &y, int i)
Check if the specified index is valid in std vector This check is 1-indexed by default.
void out_of_range(const char *function, int max, int index, const char *msg1="", const char *msg2="")
Throw an out_of_range exception with a consistently formatted message.

     [ Stan Home Page ] © 2011–2018, Stan Development Team.