Boost logo

Boost :

Subject: Re: [boost] Looking for thoughts on a new smart pointer: shared_ptr_nonnull
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2013-10-07 18:43:02


On 10/7/2013 10:48 PM, Quoth Thorsten Ottosen:
> If the idea is to be 100% shared_ptr interface compatible, it may be
> easier just to extend boost::shared_ptr a little:
>
> typedef boost::shared_ptr<boost::non_nullable<T>> SharedT;

I don't like that.

If you're suggesting using a wrapper type without changing shared_ptr,
that won't work because the shared_ptr itself could still be empty, so
you haven't gained anything.

If you're suggesting specialising shared_ptr for that subtype, I don't
see any benefit in doing this over defining a new pointer type, since
you have to redefine everything in a specialisation anyway.

And there's undoubtedly some existing templated code that operates on
boost::shared_ptr<T> that would be confused by this, or at the very
least not operate efficiently by including tests for null.

> typedef boost::shared_ptr<boost::non_nullable<T>> WeakT;

I assume that was a typo. (Weak pointers are not especially useful
without being able to represent null anyway.)


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