Boost logo

Boost :

From: Gennaro Prota (gennaro_prota_at_[hidden])
Date: 2003-03-23 06:28:58

On Sat, 22 Mar 2003 20:11:23 +0000, Kevlin Henney
<kevlin_at_[hidden]> wrote:

>In article <20f001c2f09e$9e6da500$8d6c6f50_at_pc>, Terje Slettebø
><tslettebo_at_[hidden]> writes
>>Regarding the other MSVC 6 warning given in the original report, Gennaro
>>Prota has suggested using an explicit "!=", rather than relying on the
>>implicit conversion from pointer to bool. This also avoids using a cast,
>Or one could use "stream << input && true" ;-) However, I think if one
>is going to twist the expression of the code to satisfy the misplaced
>oversensitivity of VC, it may be better to be more explicit than subtle,
>ie "!(stream << input).fail()".

That's fine too. Of course these are style/personal-taste issues. I'm
sure there's someone claiming that !! is clearer :-) More to the
point, I just suggested the way I *generally* use to shut up VC in
such cases; it' obvious that !(expr).fail() is something rather
stream-specific, whereas an explicit compare with != works any time
you have a boolean conversion.

The typical case where that warning appears with VC++ is when you
attempt to return directly the result of an API call that returns a
BOOL from a function that returns bool; e.g.:

bool IsThereAMouseHere() {
    return ::GetSystemMetrics(SM_MOUSEPRESENT);

In that case an explicit compare with FALSE seems reasonable.


Boost list run by bdawes at, gregod at, cpdaniel at, john at