check_positive_size.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_ERR_CHECK_POSITIVE_SIZE_HPP
2 #define STAN_MATH_PRIM_SCAL_ERR_CHECK_POSITIVE_SIZE_HPP
3 
5 #include <sstream>
6 #include <string>
7 
8 namespace stan {
9 namespace math {
10 
11 /**
12  * Check if <code>size</code> is positive.
13  *
14  * @param function Function name (for error messages)
15  * @param name Variable name (for error messages)
16  * @param expr Expression for the dimension size (for error messages)
17  * @param size Size value to check
18  *
19  * @throw <code>std::invalid_argument</code> if <code>size</code> is
20  * zero or negative.
21  */
22 inline void check_positive_size(const char* function, const char* name,
23  const char* expr, int size) {
24  if (size <= 0) {
25  std::stringstream msg;
26  msg << "; dimension size expression = " << expr;
27  std::string msg_str(msg.str());
28  invalid_argument(function, name, size, "must have a positive size, but is ",
29  msg_str.c_str());
30  }
31 }
32 
33 } // namespace math
34 } // namespace stan
35 #endif
const XML_Char * name
Definition: expat.h:151
void check_positive_size(const char *function, const char *name, const char *expr, int size)
void invalid_argument(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
int size(const std::vector< T > &x)
Definition: size.hpp:17
enum BeamMode string