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-03 03:02:04

On Wed, Oct 2, 2013 at 9:48 PM, Julian Gonggrijp <j.gonggrijp_at_[hidden]> wrote:
> Andrey Semashev wrote:
>> 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->. Maybe
>> it should be called shared_ref because of it. Thinking about it this
>> way, there is no need for reset() or constructors from pointers - only
>> assignment, emplace() and forwarding constructors. Interoperability
>> with shared_ptr can be provided as an extension (maybe with free
>> functions), but that would be just an extension, i.e. no implicit
>> conversion.
> I respectfully disagree. A reference is much more restricted than a
> smart pointer that cannot be null: it cannot change reference and it
> never owns the object it references. In summary, it mostly has the
> semantics of a second name to a previously created object.

It is true for regular references, although a reference bound to a
temporary object extends its lifetime and in this respect owns the
object. That said, it is also true that smart pointers do not exactly
mirror raw pointers (e.g. raw pointers don't delete pointed objects
and don't implement any ownership strategy).

I still think that being able to have a NULL value is a crucial
property of pointers. A pointer that doesn't have this special state
doesn't qualify as one to me.

Boost list run by bdawes at, gregod at, cpdaniel at, john at