Boost logo

Boost :

Subject: Re: [boost] [new Warnings policy] MS C4180 on the Maintenance Guidelines
From: Gottlob Frege (gottlobfrege_at_[hidden])
Date: 2009-11-17 10:18:15


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. :-)

Tony


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