C++ Logo

STD-PROPOSALS

Advanced search

Subject: Re: [std-proposals] Ptr proposal: looking for feedback
From: Manuel Bergler (berglerma_at_[hidden])
Date: 2020-07-16 18:06:45


Am Fr., 17. Juli 2020 um 00:32 Uhr schrieb Jefferson Carpenter via
Std-Proposals <std-proposals_at_[hidden]>:
>
> I see what you mean. The key difference is that std::unique_ptr and
> std::shared_ptr /always/ manage ownership (implicitly or by refcount).
> On the other hand, ptr ought to be usable in cases where you want to
> call functions whose argument type is ptr<T>, but you do not want the
> ptr to take ownership. For instance, you might have a T* that you've
> allocated separately and want to pass to a function taking a ptr. Or
> you might happen to have a stack-allocated value that you want to pass.
>
> Foo f;
> func(ptr(&f)); // subject to change
>
> The most natural thing for a ptr to do is to not have ownership.

If `func` doesn't take ownership, why does it take a `ptr<T>` instead
of a `T*`? Can you give an example where using `ptr<T>` as an argument
to a function that doesn't take ownership is preferable to using `T*`?
I guess that would make it clearer what you're trying to accomplish.

Best
Manuel


STD-PROPOSALS list run by herb.sutter at gmail.com

Standard Proposals Archives on Google Groups