Subject: [boost] Looking for thoughts on a new smart pointer: shared_ptr_nonnull
From: Luke Bradford (lukebradford01_at_[hidden])
Date: 2013-10-01 18:54:16
I'm new to this list, so apologies for any oversights or faux pas.
I've been finding a lot of use for a type of smart pointer I call
shared_ptr_nonnull, which is a variation on shared_ptr which is never
allowed to be empty. Specifically:
(1) It doesn't have reset() with no arguments, doesn't have a default
constructor, and doesn't have implicit conversion to bool (which would
always be true.)
(2) It throws an exception whenever there's an attempt to make it empty,
i.e. in constructors, reset, assignment, and swap.
For convenience, it's implicitly convertible to shared_ptr, and I have all
of shared_ptr's templated operators implemented with possible combinations
of shared_ptr and shared_ptr_nonnull. Usually it can be used just by
changing the type of a shared_ptr.
We have a lot of shared_ptrs, especially member variables, which are
claimed to be "always valid" and this class enforces that, at compile time
(1) and runtime (2).
Has there been any discussion of something like this? Does anybody have any
thoughts, suggestions, criticisms? Who's in charge of the smart pointer
library these days?
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk