11#ifndef TLX_DIE_CORE_HEADER
12#define TLX_DIE_CORE_HEADER
35#define tlx_die_with_sstream(msg) \
37 std::ostringstream oss__; \
38 oss__ << msg << " @ " << __FILE__ << ':' << __LINE__; \
39 ::tlx::die_with_message(oss__.str()); \
46 tlx_die_with_sstream("DIE: " << msg); \
65#define tlx_die_unless(X) \
68 ::tlx::die_with_message( \
69 "DIE: Assertion \"" #X "\" failed!", __FILE__, __LINE__); \
75#define tlx_die_if(X) \
78 ::tlx::die_with_message( \
79 "DIE: Assertion \"" #X "\" succeeded!", __FILE__, __LINE__); \
85#define tlx_die_verbose_unless(X, msg) \
88 tlx_die_with_sstream( \
89 "DIE: Assertion \"" #X "\" failed!\n" << msg << '\n'); \
95#define tlx_die_verbose_if(X, msg) \
98 tlx_die_with_sstream( \
99 "DIE: Assertion \"" #X "\" succeeded!\n" << msg << '\n'); \
107template <
typename TypeA,
typename TypeB>
115 return std::strcmp(a, b) == 0;
121 return a != a ? b != b : a == b;
127 return a != a ? b != b : a == b;
132#define tlx_die_unequal(X, Y) \
136 if (!::tlx::die_equal_compare(x__, y__)) { \
137 tlx_die_with_sstream("DIE-UNEQUAL: " #X " != " #Y " : " \
138 "\"" << x__ << "\" != \"" << y__ << "\""); \
145#define tlx_assert_equal(X, Y)
147#define tlx_assert_equal(X, Y) die_unequal(X, Y)
153#define tlx_die_verbose_unequal(X, Y, msg) \
157 if (!::tlx::die_equal_compare(x__, y__)) { \
158 tlx_die_with_sstream("DIE-UNEQUAL: " #X " != " #Y " : " \
159 "\"" << x__ << "\" != \"" << y__ << "\"\n" << \
168template <
typename Type>
170 return t < 0 ? -t : t;
174template <
typename TypeA,
typename TypeB>
182#define tlx_die_unequal_eps(X, Y, eps) \
186 if (!::tlx::die_equal_eps_compare(x__, y__, eps)) { \
187 tlx_die("DIE-UNEQUAL-EPS: " #X " != " #Y " : " \
188 << std::setprecision(18) \
189 << "\"" << x__ << "\" != \"" << y__ << "\""); \
196#define tlx_die_verbose_unequal_eps(X, Y, eps, msg) \
200 if (!::tlx::die_equal_eps_compare(x__, y__, eps)) { \
201 tlx_die("DIE-UNEQUAL-EPS: " #X " != " #Y " : " \
202 << std::setprecision(18) \
203 << "\"" << x__ << "\" != \"" << y__ << "\"\n" << \
210#define tlx_die_unequal_eps6(X, Y) \
211 die_unequal_eps(X, Y, 1e-6)
216#define tlx_die_verbose_unequal_eps6(X, Y, msg) \
217 die_verbose_unequal_eps(X, Y, 1e-6, msg)
224#define tlx_die_equal(X, Y) \
228 if (::tlx::die_equal_compare(x__, y__)) { \
229 tlx_die_with_sstream("DIE-EQUAL: " #X " == " #Y " : " \
230 "\"" << x__ << "\" == \"" << y__ << "\""); \
237#define tlx_assert_unequal(X, Y)
239#define tlx_assert_unequal(X, Y) die_equal(X, Y)
245#define tlx_die_verbose_equal(X, Y, msg) \
249 if (::tlx::die_equal_compare(x__, y__)) { \
250 tlx_die_with_sstream("DIE-EQUAL: " #X " == " #Y " : " \
251 "\"" << x__ << "\" == \"" << y__ << "\"\n" << \
260#define tlx_die_unless_throws(code, exception_type) \
265 catch (const exception_type&) { \
268 ::tlx::die_with_message( \
269 "DIE-UNLESS-THROWS: " #code " - NO EXCEPTION " #exception_type, \
270 __FILE__, __LINE__); \
DieException(const std::string &message)
Type die_unequal_eps_abs(const Type &t)
simple replacement for std::abs
void die_with_message(const std::string &msg)
die with message - either throw an exception or die via std::terminate()
bool die_equal_compare(TypeA a, TypeB b)
helper method to compare two values in die_unequal()
bool set_die_with_exception(bool b)
Switch between dying via std::terminate() and throwing an exception.
bool die_equal_eps_compare(TypeA x, TypeB y, double eps)
helper method to compare two values in die_unequal_eps()