C++ Logo

std-discussion

Advanced search

Re: Making the new expression smart

From: Richard Hodges <hodges.r_at_[hidden]>
Date: Thu, 17 Sep 2020 22:51:18 +0200
On Thu, 17 Sep 2020 at 21:23, Christopher Head via Std-Discussion <
std-discussion_at_[hidden]> wrote:

> On Thu, 17 Sep 2020 21:13:30 +0200
>
> Richard Hodges via Std-Discussion <std-discussion_at_[hidden]>
>
> wrote:
>
>
>
> > In this case, yes. But then so does initialising a shared_ptr with a
>
> > naked pointer, so nothing would be lost.
>
>
>
> I think it’s a perspective thing. Today people generally try to avoid
>
> using new because it returns raw pointers, so make_unique and
>
> make_shared are common. I figured the point of changing operator new to
>
> return smart pointers would be to use new more and get away from the
>
> make_foo functions, at which point the double-allocation problem would
>
> arise.
>

I am not arguing for or against this idea. I am merely making a few
observations.

Expanding on the OP’s idea, one could envisage the following syntax:

auto a = new (unique) Foo ();
auto b = new (shared) Foo ();

It could be argued that this is expressive.
It could also be argued that it’s merely syntactic sugar for make_unique
and make_shared.

Personally I tend to prefer keywords that express intent rather than
library functions, but this is probably a minority view amongst the
participants of WG21.


> --
>
> Christopher Head
>
> --
>
> Std-Discussion mailing list
>
> Std-Discussion_at_[hidden]
>
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>
> --
Richard Hodges
hodges.r_at_[hidden]
office: +442032898513
home: +376841522
mobile: +376380212

Received on 2020-09-17 15:51:32