Boost logo

Boost :

Subject: Re: [boost] [new Warnings policy] MS C4180 on the Maintenance Guidelines
From: Paul A. Bristow (pbristow_at_[hidden])
Date: 2009-11-17 11:22:38


> -----Original Message-----
> From: boost-bounces_at_[hidden] [mailto:boost-bounces_at_[hidden]] On
Behalf Of
> Mateusz Loskot
> Sent: Tuesday, November 17, 2009 3:36 PM
> To: boost_at_[hidden]
> 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_at_[hidden]> 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)
>
> http://www.artima.com/cppsource/safebool.html

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_at_[hidden]

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