C++ Logo


Advanced search

Re: Easier make_unique with deleter function

From: Thiago Macieira <thiago_at_[hidden]>
Date: Mon, 23 Aug 2021 14:46:03 -0700
On Monday, 23 August 2021 09:56:58 PDT Ville Voutilainen via Std-Proposals
> > 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.

True, but you may want to encode everything in the type, to avoid storing an
extra 8 bytes to make the indirect function call. That's likely the most
common use-case, as TIFF* gets freed with TIFFClose and FILE* with fclose. Of
course, if you do that, you'd have to use a different std::unique_ptr
instantiation if you want your FILE* to be closed with pclose instead.

Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DPG Cloud Engineering

Received on 2021-08-23 16:46:09