C++ Logo

std-proposals

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

Yup.

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
https://code.qt.io/cgit/qt/qtbase.git/commit/?
id=211369133cf40b2f522caaff259c19069ed23ca4

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).

Though

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

and

  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