I’m looking for a way to add custom messages to assert statements.
I found this questions Add custom messages in assert? but the message is static there. I want to do something like this:
assert((0 < x) && (x < 10), std::string("x was ") + myToString(x));
When the assertion fails I want the normal output plus for example "x was 100".
You are out of luck here. The best way is to define your own
assertmacro.Basically, it can look like this:
This will define the
ASSERTmacro only if the no-debug macroNDEBUGisn’t defined.Then you’d use it like this:
Which is a bit simpler than your usage since you don’t need to stringify
"x was "andxexplicitly, this is done implicitly by the macro.