Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2005-04-04 12:39:24


Ben Hutchings wrote:
> Daniel James wrote:
>> Ah, I just found out why I didn't do this before - prev_ptr might be
>> a pointer object (depending on the allocator), so the correct line
>> is: return (*prev_ptr) != link_ptr();
>>
>> Which can potentially be inefficient. I think the best thing to do
>> is to use a pragma to disable the warning,
>
> If it's the warning I'm thinking of (C4800: "forcing value to bool
> 'true' or 'false'" - well, *duh*) then this is the right approach.
>
>> or maybe:
>>
>> return static_cast<bool>(*prev_ptr);
>>
>> or:
>>
>> return boost::implicit_cast<bool>(*prev_ptr);
>>
>> would work.
>
> Neither of those prevents the warning.

    return *prev_ptr? true: false;

is what I use. The compiler is right, by the way, forcing the value to bool
does indeed produce suboptimal code, whereas the above workaround does not
:-)


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net