making assert(…) even more informative

If you are like me, you use assert all over the place. Even when compiled out, it serves are useful documentation as to what is going on (or what is supposed to be going on).  I recently learned another trick that I could have been using for the past 30 years, even when I first met C in the early 1980s.

Previously, I wrote about making assert(0) more informative, by adding text that will appear in the output if the assert fails.

It is possible to make ordinary asserts more informative, too.

assert(payload.size() == 1 && “must be exactly one chunk in payload”);

The string constant is effectively a boolean true, and thus the sense of the condition is unaltered by the string constant, however the string constant is carried through to the output, should the assert fail.