Boost logo

Boost :

Subject: Re: [boost] [gsoc] Pointer Plus Bits Behavior and Interface
From: Joaquin M Lopez Munoz (joaquin_at_[hidden])
Date: 2010-07-15 12:07:05


Brian Bartman <bbartmanboost <at> gmail.com> writes:

>
> Would it be better to make the pointer_plus_bits convertible to a boolean
> based on the value of the pointer being stored? This would allow it to be
> more like to a pointer being that you could, as many people do, put it
> inside of an if statement to check to see if its null.

Converting to bool can be problematic, as throughly explained at

http://www.informit.com/articles/article.aspx?p=31529&seqNum=8

The optimum way to do this is to convert to a pointer of a private
type which is null if and only if the stored pointer is null.
This is explained also at the reference above and it's the way
boost::shared_ptr implements "conversion to bool semantics" (take
a look at the source for inspiration).

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo


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