Boost logo

Boost :

Subject: Re: [boost] Looking for thoughts on a new smart pointer: shared_ptr_nonnull
From: Luke Bradford (lukebradford01_at_[hidden])
Date: 2013-10-02 08:24:26


To Andrey's point:

> Anyway, I think, such a pointer does not behave like a real pointer,
> so it shouldn't be called as such. It looks more like a reference,
> except that the referred object is accessed through operator->.

Well, shared_ptr_nonnull does behave like a ref counted object in many
respects - with the notable exception that it can point to different
objects over the course of its lifetime. I find this to be a useful
property and a good reason to call it a pointer. And I find the
interchangeability with shared_ptr very useful as well.

Julian, I'm curious to see your proposed pointer too.

On Wed, Oct 2, 2013 at 8:03 AM, Julian Gonggrijp <j.gonggrijp_at_[hidden]>wrote:

> Luke Bradford wrote:
>
> > 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.)
> > [...]
> >
> > 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?
>
> I think it makes a lot of sense to have a pointer that can't be null
> and doesn't have a default constructor. Default construction isn't
> always possible. Otherwise it's against the intuition that a default
> constructor shouldn't allocate memory. Explicit initialization has
> inherent value as well, especially for pointers.
>
> Coincidentally I've recently been working on a different kind of smart
> pointer which has these same properties (no reset, no default ctor, no
> implicit conversion to bool). Even more coincidentally I might gauge
> interest today. Please don't let this distract you though; my smart
> pointer is quite different in other respects.
>
> -Julian
>
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>


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