|
Boost : |
From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2002-05-08 12:26:29
----- Original Message -----
From: "Greg Colvin" <greg_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Wednesday, May 08, 2002 12:47 PM
Subject: Re: [boost] operator bool() for smart pointers
> At 07:13 AM 05/08/2002, Fernando wrote:
> >In addition to the safe bool included in the latest CVS version,
> >shared_ptr<> supports operator !.
> >
> >Whenever a given class supports operator ! for boolan testing, you can
> >always use the 'double bang' idiom for testing 'true':
> >
> >instead of: if (p) ...
> >write: if ( !! p ) ...
> >
> >Using this, of course, might be contrary to the user's religion :-)
since
> >it looks akward to the unaware eye; but it can be handy to know about it.
>
> It's actually a minor tenet of my religion, and Max calls it the
> "boolean conversion operator". But then I prefer &*p to p->get()
> because it works with raw pointers as well as smart pointers.
>
I have quite similar preferences too.
I don't like to use member functions for objects which represent general
concepts (such a (smart) pointer), since those are likely to be represented
as well by other classes (or a built-in type), and a member function is tied
to a specific class.
For instance, I use: peek(ptr) for the case you mention, which can also be
used for any sort of pointer. (BTW, I like your syntax better since it
doesn't require a separate function... nice!)
Fernando Cacciola
Sierra s.r.l.
fcacciola_at_[hidden]
www.gosierra.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk