for(unsigned int i = 0; i < x.size(); i++)
assert(x[i] > 0);
When not debugging (NDEBUG flag), the resultant is an empty for loop. Is there a clean way to handle this (not executing the empty for loop); preferably without preprocessor directive, since it would defeat the purpose of assert in the first place.
A good optimizer should be able to eliminate the entire loop when
NDEBUGis defined (I’ve just tested mine, and it does do that).Alternatively, you could surround the entire loop with
#ifndef NDEBUG/#endif. You say this “would defeat the purpose ofassertin the first place”, but I don’t really follow the reasoning.