Boost logo

Boost :

Subject: Re: [boost] [new Warnings policy] MS C4180 on the Maintenance Guidelines
From: Daniel James (daniel_james_at_[hidden])
Date: 2009-11-17 16:21:35


2009/11/17 Patrick Horgan <phorgan1_at_[hidden]>:
>
>   For signed integral types, using !!val folds all the negative and positive
>   non-zero values into true.  It's the equivalent of val!=0.  Sometimes,
>   people really mean to test for val!=0, sometimes they really mean val>0.
>   !!val will still be true even if val is -42.   Why not say what you mean?
>   It's communicates better and leads to less subtle bugs.  Use one of val!=0,
>   val>0, or whatever test you really mean to do.  I understand !!val is the
>   same as val!=0 when I read it and hope that the original programmer also
>   understood that.  When I maintain someone else's code, and see val!=0 I feel
>   more happy fuzzies that they said what they meant.

It's worth noting that if the warning turns up in generic code, you
should make sure your workaround doesn't add additional requirements
to the type being tested.

Daniel


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