C++ Logo

std-proposals

Advanced search

Re: [std-proposals] A non-owning but self zeroing smart pointer for single ownership

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Sat, 15 Feb 2025 18:17:51 +0100
Even for a single-threaded execution model, one could have callbacks or cooperarive multi-tasking.   I agree, at least in its simple form the idea is flawed.   -----Ursprüngliche Nachricht----- Von:Jason McKesson via Std-Proposals <std-proposals_at_[hidden]> Gesendet:Sa 15.02.2025 17:14 Betreff:Re: [std-proposals] A non-owning but self zeroing smart pointer for single ownership An:std-proposals_at_[hidden]; CC:Jason McKesson <jmckesson_at_[hidden]>; On Sat, Feb 15, 2025 at 5:12 AM Sebastian Wittmeier via Std-Proposals <std-proposals_at_[hidden]> wrote: > > If you use a weak_ptr, it is converted into ashared_ptr for the duration of access. > > So it is not enough to disallow copying to make a shared_ptr unique. True, but without the ability to lock whatever the "weak" reference is to prevent its deletion while you are using it, you could never use it in a context where threading is possible. It'd be inherently dangerous. I think this idea is just fundamentally flawed. If you want some place to be able to use it without permanently owning it, then it must be able to own it *temporarily* (otherwise, it cannot use it safely). And since it's basically impossible to prevent temporary ownership from transforming into permanent ownership, it is practically a distinction without a difference. -- Std-Proposals mailing list Std-Proposals_at_[hidden] https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2025-02-15 17:22:04