.Single ownership and a strong requirement for it to be so.


From: Std-Proposals <std-proposals-bounces@lists.isocpp.org> on behalf of Thiago Macieira via Std-Proposals <std-proposals@lists.isocpp.org>
Sent: Monday, February 24, 2025 3:22 PM
To: std-proposals@lists.isocpp.org <std-proposals@lists.isocpp.org>
Cc: Thiago Macieira <thiago@macieira.org>
Subject: Re: [std-proposals] A non-owning but self zeroing smart pointer for single ownership
 
On Monday, 24 February 2025 03:26:32 Brasilia Standard Time Robin Savonen
Söderholm via Std-Proposals wrote:
> But I am not sure if we are getting any advantage over shared_ptr.

I've been wondering the same: under what conditions would the proposed class
here be used instead of shared_ptr and weak_ptr?

The class proposed here looks like Qt's QPointer (which has been mentioned),
but that has some important differences:
* it requires the pointed object to derive from QObject
* it reports deletion thread-safely, but it doesn't guarantee the object won't
  get deleted on the next instance

QPointer is implemented using *the exact same* mechanism as QWeakReference and
QSharedPointer, except you can't "lock" the object into a QSharedPointer (you
can't prevent destruction). So if this proposed class were also implemented
using the same ref-counted ref-counter structure block, it would be even more
reason to ask why not use std::shared_pointer in the first place.

--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel DCAI Platform & System Engineering



--
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals