
12 Mar
2010
12 Mar
'10
7:51 p.m.
on 12.03.2010 at 20:34 Steven Watanabe wrote :
but to check if the arg converts to bool we can write something like
#define assert(cond) sizeof(bool(cond))
#define assert(cond) sizeof(bool(cond)) int main() { int i = 0; assert(i); }
warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning) i guess static_cast will work i.e. #define assert(cond) sizeof(static_cast<bool>(cond))
or something like #define assert(cond) sizeof(cond ? char : int)
which may or may not expand to some code (i.e. machine instructions) If this isn't completely optimized away, and you actually care, you should get a better compiler. is that your own motto or the boost one? my point is: it's not always possible to do that
-- Pavel