Boost logo

Boost :

Subject: Re: [boost] suggestion on assertion macros
From: DE (satan66613_at_[hidden])
Date: 2010-03-12 14:51:50


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

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk