All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups
check_size_match.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_PRIM_SCAL_ERR_CHECK_SIZE_MATCH_HPP
#define STAN_MATH_PRIM_SCAL_ERR_CHECK_SIZE_MATCH_HPP
#include <boost/type_traits/common_type.hpp>
#include <stan/math/prim/scal/err/invalid_argument.hpp>
#include <stan/math/prim/scal/meta/likely.hpp>
#include <sstream>
#include <string>
namespace stan {
namespace math {
template <typename T_size1, typename T_size2>
inline bool check_size_match(const char* function,
const char* name_i,
T_size1 i,
const char* name_j,
T_size2 j) {
if (likely(i == static_cast<T_size1>(j)))
return true;
std::ostringstream msg;
msg << ") and "
<< name_j << " (" << j << ") must match in size";
std::string msg_str(msg.str());
invalid_argument(function, name_i, i,
"(", msg_str.c_str());
return false;
}
template <typename T_size1, typename T_size2>
inline bool check_size_match(const char* function,
const char* expr_i,
const char* name_i,
T_size1 i,
const char* expr_j,
const char* name_j,
T_size2 j) {
if (likely(i == static_cast<T_size1>(j)))
return true;
std::ostringstream updated_name;
updated_name << expr_i << name_i;
std::string updated_name_str(updated_name.str());
std::ostringstream msg;
msg << ") and "
<< expr_j << name_j
<< " (" << j << ") must match in size";
std::string msg_str(msg.str());
invalid_argument(function, updated_name_str.c_str(), i,
"(", msg_str.c_str());
return false;
}
}
}
#endif
invalid_argument.hpp
stan::math::invalid_argument
void invalid_argument(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
Throw an invalid_argument exception with a consistently formatted message.
Definition: invalid_argument.hpp:31
stan::math::check_size_match
bool check_size_match(const char *function, const char *name_i, T_size1 i, const char *name_j, T_size2 j)
Return true if the provided sizes match.
Definition: check_size_match.hpp:30
likely.hpp
likely
#define likely(x)
Definition: likely.hpp:8

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