|
Boost : |
Subject: Re: [boost] [new Warnings policy] MS C4180 on the Maintenance Guidelines
From: Paul A. Bristow (pbristow_at_[hidden])
Date: 2009-11-18 11:14:26
> -----Original Message-----
> From: boost-bounces_at_[hidden] [mailto:boost-bounces_at_[hidden]] On
Behalf Of
> Scott McMurray
> Sent: Wednesday, November 18, 2009 3:19 PM
> To: boost_at_[hidden]
> Subject: Re: [boost] [new Warnings policy] MS C4180 on the Maintenance
Guidelines
>
> 2009/11/18 Paul A. Bristow <pbristow_at_[hidden]>:
> >
> > I note that this will mean quite a lot of work for some people as "if (ptr)
..."
> > is such a common (and IMO dreadful) idiom.
> >
>
> What do you propose as a superior idiom that will work with pointers,
> smart pointers, optional, ...?
> Slapping double-exclamation points everywhere is no better.
!! is not mentioned in the draft Guidelines, following feedback.
The 'safe bool' idiom http://www.artima.com/cppsource/safebool.html might be,
but that may be getting into too much detail.
I am proposing
if (prt != 0)
{
...// do something with pointer as it is meaningful.
}
As several people have observed, this expresses exactly what you mean, showing
that prt == 0 is a special case, rather than saving a few keystrokes. It may be
obvious for pointers, but having an 'invalid or special' value is used widely
elsewhere.
Or if that is considered too much work, suppressing the warning (locally to that
module).
Let's not flagellate ourselves too much over this ;-)
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