Boost logo

Boost :

Subject: Re: [boost] Why no non-null smart pointers?
From: Jeff Hill (johill_at_[hidden])
Date: 2014-04-28 11:20:35

Ross MacGregor wrote
> "Johan RÃ¥de" <

> rade_at_.lth

> > wrote in message
> news:ft10ag$6nn$

> 1_at_.gmane

> ...
> I know it is an insane idea to suggest changing the entire
> boost::smart_ptr library to a boost::smart_ref library, but I
> think it may actually be the right thing to do. Does anyone
> agree?

I also find the nill state of shared_ptr to be a liability when designing
interfaces. The primary purpose of shared_ptr when used in an interface
context is to convey ownership, and almost always it feels wrong to also
provide simultaneously an option to convey ownership of nothing. The poor
user is left with the responsibility of testing every shared_ptr he has
received for null state before using it, but its easy to forget and the
compiler provides no assistance. Ultimately, the library interface based on
shared_ptr is more error prone, less likely to be easy to use, and therefore
arguably suboptimal.

Of course no one suggests that shared_ptr should (or could) be changed in
ways that impacts backwards compatibility, but I have to agree with the
author of the post that this issue can be identified as a legitimate cause
for concern.


View this message in context:
Sent from the Boost - Dev mailing list archive at

Boost list run by bdawes at, gregod at, cpdaniel at, john at