Date: Mon, 23 Aug 2021 19:56:58 +0300
On Mon, 23 Aug 2021 at 19:32, Phil Endecott via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> Dear Experts,
>
> I have been contemplating what the easiest current or future
> way to create a unique_ptr with a custom deleter function is.
>
> For example, libtiff has
>
> TIFF* TIFFOpen(args);
> void TIFFClose(TIFF*);
>
> I'd like to be able to write something like:
>
> auto tiffp = make_unique_with_deleter( TIFFOpen(fn), TIFFClose );
>
> Of course it can't be quite that simple.
Why not? https://wandbox.org/permlink/6wZezfaxA2GDWi1o
> Fundamentally unique_ptr
> stores the deleter only in the type, which I think means the
> deleter function can only ever be a template parameter:
I don't quite follow. unique_ptr does store a deleter object, not just
its type. It has
http://eel.is/c++draft/unique.ptr.single.ctor#10 for exactly this purpose.
<std-proposals_at_[hidden]> wrote:
>
> Dear Experts,
>
> I have been contemplating what the easiest current or future
> way to create a unique_ptr with a custom deleter function is.
>
> For example, libtiff has
>
> TIFF* TIFFOpen(args);
> void TIFFClose(TIFF*);
>
> I'd like to be able to write something like:
>
> auto tiffp = make_unique_with_deleter( TIFFOpen(fn), TIFFClose );
>
> Of course it can't be quite that simple.
Why not? https://wandbox.org/permlink/6wZezfaxA2GDWi1o
> Fundamentally unique_ptr
> stores the deleter only in the type, which I think means the
> deleter function can only ever be a template parameter:
I don't quite follow. unique_ptr does store a deleter object, not just
its type. It has
http://eel.is/c++draft/unique.ptr.single.ctor#10 for exactly this purpose.
Received on 2021-08-23 11:57:15