C++ Logo


Advanced search

Re: Easier make_unique with deleter function

From: Thiago Macieira <thiago_at_[hidden]>
Date: Mon, 23 Aug 2021 15:22:15 -0700
On Monday, 23 August 2021 15:04:42 PDT Ville Voutilainen wrote:
> I can do that without changing the client-side invocation of this
> function too much:
> https://wandbox.org/permlink/NBG9PbfxHbNniudX


But going back to the OP's point: shouldn't such functionality be in the
standard? Like std::make_unique itself, which simply helps in typing less
(unlike std::make_shared, which has a benefit in number of allocations).

I needed it two weeks ago for

but didn't bother with encoding the deleter in the type because it required an
extra level of indirection for something that never left the function, so I
trusted the optimiser to do the right thing (disassembler proves GCC did).


  make_unique_with_just_type_deleter(TIFFOpen(), [](TIFF* t) {TIFFClose(t);});


  make_unique_with_just_type_deleter(TIFFOpen(), TIFFClose);

Do the same thing, but one is half the size of the other.

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

Received on 2021-08-23 17:22:23