always_assert.hpp

A more dynamic replacement for standard library asserts. Status: RELEASE.

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

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

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

  • If a literal string is provided as an argument, it will be printed as an error message.

  • if EMP_TDEBUG is defined, emp_assert() goes into test mode and records failures, but does not abort. (useful for unit tests of asserts)

Example:

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

Unlike “emp_assert”, “emp_always_assert” will trigger an assertion error whether compiled in debug mode or not.

Defines

emp_always_assert_impl(...)
emp_always_assert(...)

Require a specified condition to be true. If it is false, immediately halt execution. Print also extra information on any variables or expressions provided as variadic args. Will be evaluated when compiled in both debug and release mode.