assert_warning.hpp

A non-terminating replacement for standard library asserts.

A supplement for the system-level assert.h, called “emp_assert_warning” Added functionality:

  • If compiled with Emscripten, will provide pop-up alerts in a web browser.

  • emp_assert_warning can take additional arguments. If the assert is triggered, those extra arguments will be evaluated and printed.

  • if NDEBUG -or- EMP_NDEBUG is defined, the expression in emp_assert_warning() is not evaluated.

  • emp_assert_warning() records failures, but does not abort.

Example:

int a = 6; emp_assert_warning(a==5, a);

When compiled in debug mode (i.e., without the -DNDEBUG flag), this will spring an assertion error and print the value of a.

Defines

emp_assert_warning(...)

NDEBUG should trigger its EMP equivalent.

Require a specified condition to be true. If it is false, print extra information on any variables or expressions provided as variadic args. Note: If NDEBUG is defined, emp_assert_warning() will not do anything. Due to macro parsing limitations, extra information will not be printed when compiling with MSVC.