C++ Logo

std-proposals

Advanced search

Re: Easier make_unique with deleter function

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Mon, 23 Aug 2021 19:21:59 -0400
On Mon, Aug 23, 2021 at 6:23 PM Thiago Macieira via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> 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).

`make_unique` was not added because it was shorter to type. In a
pre-C++17 world, you couldn't guarantee that two argument expressions
in the same function call would not interleave with one another. As
such, `make_unique<T>(Args)` was a more exception-safe version of
`unique_ptr<T>(Args)`.

Of course, since C++17 fixed the problem at the language level (the
argument expressions can happen in any order, but the sub-expressions
cannot be interleaved), it has become unnecessary.

So from that perspective, I'd say that we don't need a
`make_unique_with_delete` at all.

Received on 2021-08-23 18:22:12