|
Boost : |
Subject: Re: [boost] Looking for thoughts on a new smart pointer: shared_ptr_nonnull
From: Julian Gonggrijp (j.gonggrijp_at_[hidden])
Date: 2013-10-02 08:03:17
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
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk