Boost logo

Boost :

Subject: Re: [boost] Looking for thoughts on a new smart pointer: shared_ptr_nonnull
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2013-10-04 09:51:01


On Friday 04 October 2013 15:39:23 Thorsten Ottosen wrote:
> On 03-10-2013 21:55, Matt Calabrese wrote:
> > On Thu, Oct 3, 2013 at 9:37 AM, Thorsten Ottosen <
> >
> > thorsten.ottosen_at_[hidden]> wrote:
> >> shared_obj<Foo> sharedFoo = make_shared_obj( 42, "foo" );
> >>
> >> would be good names.
> >
> > The only issue with this is your type may not be allocated with new and
> > you
> > may want a custom deleter (you may also want to take control from a
> > separately allocated object). These are things that shared_ptr can handle,
> > but with a strict interface such as this, the non-null ptr cannot. That
> > said, I personally don't care, but if the intent is to just have a
> > non-null
> > shared_ptr then we shouldn't be sacrificing existing functionality. It
> > should simply be a shared_ptr with a non-null invariant and that is that.
>
> The deleter thing can probably be handled with a consrtuctor like
>
> template< class D, class Args ... >
> shared_obj( D, Args args... );
>
> For stuff not allocated via new, it can be probably be handled by
> another version of make_shared_obj.

I'd suggest both cases to be handled by special factory functions. Otherwise,
it is ambiguous whether the first constructor argument is a deleter or an
argument to the object constructor.


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