Hi Thiago,

what is the relevance of the inheritance from QObject for QPointer?
 

-----Ursprüngliche Nachricht-----
Von: Thiago Macieira via Std-Proposals <std-proposals@lists.isocpp.org>
Gesendet: Mo 24.02.2025 15:22
Betreff: Re: [std-proposals] A non-owning but self zeroing smart pointer for single ownership
An: std-proposals@lists.isocpp.org;
CC: Thiago Macieira <thiago@macieira.org>;
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