I’ve ran several times into a situation, where it would have been useful to have an assertion, which was conditional in nature. See the following idea:
if (if_this_is_true)
jassert(test_this_and_that);
I.e. the “if” statement was a prerequisite for the test to be valid.
So I would propose an extra jassert() method, which would let the user add that prerequisite test for the assertion. The above example would then be written in the form of:
jassertIf(if_this_is_true, test_this_and_that);
Could something like that be added into JUCE? Maybe just add the below piece of code into JUCE:
#define jassertIf(prerequisite, expression) JUCE_BLOCK_WITH_FORCED_SEMICOLON (if (prerequisite) if (! (expression)) jassertfalse;)
The !prerequisite || expression means: “If prerequisite is false, pass without checking expression. If prerequisite is true, check expression”.
Note that this is different from the suggestion so far:
jassert(if_this_is_true && test_this_and_that);
This one would fail the assertion if if_this_is_true is false. But you want to skip the entire jassert check in that case.
It would also skip (pass) the check if if_this_is_true is true. Which is the opposite from what you asked.