libassert
libassert copied to clipboard
ASSERT or variant returning result of the expression (not just left-hand operand)
Hi,
One thing that I currently use pretty often (especially for networking code) is:
if (!AssertTrue(a > 3)) {
// Handle the failed assertion in release
return;
}
This allows crashing in debug builds during testing but handling it without crashing for users in release builds.
It looks very similar to:
if (!ASSERT_VAL(a > 3))
but ASSERT_VAL
returns the value of a
, not the result of the whole expression a > 3
.
Obviously it's possible to do
if (ASSERT_VAL(a > 3) <= 3)
but that makes it complicated and error-prone.
Would it be possible to return the result of the whole expression from ASSERT
, or to create a variant of the macro (e.g. ASSERT_THAT
) that returns the result?