As a rule, when I erase an element from a set, I want to claim that it was actually deleted: that is
assert(s.erase(e));
but then the item is not erased when installing NDEBUG. But if I write
bool removed = s.erase(e); assert(removed);
the compiler complains that 'remove' is not used when NDEBUG is installed.
How can I do it right?
In the end, I just created a utility method:
inline void run_and_assert(bool b) { assert(b); }
now i can say
run_and_assert(s.erase(e));
Are there any flaws? It seems easier than luiscubal solution
c ++ coding-style assert compiler-warnings boolean-expression
dspyz
source share