Stan  1.3
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
check_range.hpp
Go to the documentation of this file.
1 #ifndef __STAN__MATH__MATRIX__CHECK_RANGE_HPP__
2 #define __STAN__MATH__MATRIX__CHECK_RANGE_HPP__
3 
4 #include <sstream>
5 #include <stdexcept>
6 
7 namespace stan {
8  namespace math {
9 
10  namespace {
11 
12  void raise_range_error(size_t max,
13  size_t i,
14  const char* msg,
15  size_t idx) {
16  std::stringstream s;
17  s << "INDEX OPERATOR [] OUT OF BOUNDS"
18  << "; index=" << i
19  << "; lower bound=1"
20  << "; upper bound=" << max
21  << "; index position=" << idx
22  << "; " << msg
23  << std::endl;
24  throw std::out_of_range(s.str());
25  }
26 
27  }
28 
29  inline
30  void check_range(size_t max,
31  size_t i,
32  const char* msg,
33  size_t idx) {
34  if (i < 1 || i > max)
35  raise_range_error(max,i,msg,idx);
36  }
37 
38 
39  }
40 }
41 #endif

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