14 #ifndef HELIB_ASSERTIONS_H
15 #define HELIB_ASSERTIONS_H
17 #include <helib/exceptions.h>
60 template <
typename ExceptionTy = ::helib::LogicError,
typename T =
void>
61 inline void assertTrue(
const T& value,
const std::string& message)
63 static_assert(std::is_base_of<::helib::Exception, ExceptionTy>::value,
64 "ExceptionTy must inherit from helib::Exception");
65 static_assert(std::is_same<bool, T>::value,
"Type T is not boolean");
67 throw ExceptionTy(message);
82 template <
typename ExceptionTy = ::helib::LogicError,
typename T =
void>
85 static_assert(std::is_same<bool, T>::value,
"Type T is not boolean");
86 static_assert(std::is_base_of<::helib::Exception, ExceptionTy>::value,
87 "ExceptionTy must inherit from helib::Exception");
89 throw ExceptionTy(message);
107 template <
typename ExceptionTy = ::helib::LogicError,
typename T =
void>
108 inline void assertEq(
const T& a,
const T& b,
const std::string& message)
110 static_assert(std::is_base_of<::helib::Exception, ExceptionTy>::value,
111 "ExceptionTy must inherit from helib::Exception");
114 throw ExceptionTy(message);
132 template <
typename ExceptionTy = ::helib::LogicError,
typename T =
void>
133 inline void assertNeq(
const T& a,
const T& b,
const std::string& message)
135 static_assert(std::is_base_of<::helib::Exception, ExceptionTy>::value,
136 "ExceptionTy must inherit from helib::Exception");
139 throw ExceptionTy(message);
155 template <
typename ExceptionTy = ::helib::LogicError,
typename T =
void>
158 static_assert(std::is_base_of<::helib::Exception, ExceptionTy>::value,
159 "ExceptionTy must inherit from helib::Exception");
161 throw ExceptionTy(message);
182 template <
typename ExceptionTy = ::helib::OutOfRangeError,
typename T =
void>
186 const std::string& message,
187 bool right_inclusive =
false)
189 static_assert(std::is_base_of<::helib::Exception, ExceptionTy>::value,
190 "ExceptionTy must inherit from helib::Exception");
191 bool min_less = min <= elem;
193 throw ExceptionTy(message);
195 bool max_great = right_inclusive ? elem <= max : elem < max;
197 throw ExceptionTy(message);
202 #endif // End of header guard