Automatic Differentiation
 
Loading...
Searching...
No Matches
out_of_range.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_ERR_OUT_OF_RANGE_HPP
2#define STAN_MATH_PRIM_ERR_OUT_OF_RANGE_HPP
3
5#include <typeinfo>
6#include <sstream>
7#include <stdexcept>
8
9namespace stan {
10namespace math {
11
27inline void out_of_range(const char* function, int max, int index,
28 const char* msg1 = "", const char* msg2 = "") {
29 std::ostringstream message;
30 message << function << ": accessing element out of range. "
31 << "index " << index << " out of range; ";
32
33 if (max == 0) {
34 message << "container is empty and cannot be indexed" << msg1 << msg2;
35 } else {
36 message << "expecting index to be between " << stan::error_index::value
37 << " and " << stan::error_index::value - 1 + max << msg1 << msg2;
38 }
39 throw std::out_of_range(message.str());
40}
41
42} // namespace math
43} // namespace stan
44#endif
auto max(T1 x, T2 y)
Returns the maximum value of the two specified scalar arguments.
Definition max.hpp:25
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.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Definition fvar.hpp:9