
-----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Mateusz Loskot Sent: Tuesday, November 17, 2009 3:36 PM To: boost@lists.boost.org Subject: Re: [boost] [new Warnings policy] MS C4180 on the Maintenance Guidelines
Gottlob Frege wrote:
On Mon, Nov 16, 2009 at 4:08 PM, Patrick Horgan <phorgan1@gmail.com> wrote:
C4800 Might suggest that they use a bool valued expression in the first place, i.e. instead of foo, foo!=0, or do a static cast to bool. This is at times indicative of real bugs, when people turn out to not be doing what they thought they were doing. Apparently this is one of my favorite bugs (by favorite I don't mean that I like it either!)
C4800: int' : forcing value to bool 'true' or 'false'
I'm a big fan of using !! to convert to bool:
bool has_item() { Foo * foo = find_item();
return !!foo; // convert ptr to bool }
Is that too subtle for others? It wouldn't be too subtle if it became a common idiom. :-)
It looks like a quite recommended idiom (double-bang trick)
Looks OK to me but anyone 'deprecating' this before I add it to the guidelines? Are we sure that all compilers can evaluate this as compile time - otherwise while debugging users might find it a pest? Paul --- Paul A. Bristow Prizet Farmhouse Kendal, UK LA8 8AB +44 1539 561830, mobile +44 7714330204 pbristow@hetp.u-net.com