C++ Logo

std-discussion

Advanced search

Re: Making the new expression smart

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

> On Thu, 17 Sep 2020 13:56:28 +0430
>
> Farid Mehrabi via Std-Discussion <std-discussion_at_[hidden]>
>
> wrote:
>
>
>
> > This in
>
> > turn would enable the new expression to return a smart pointer -
>
> > rather than a dangerous raw pointer:
>
>
>
> As it stands today, I can hold Widgets in complex data structures using
>
> shared_ptrs, and I can also hold Widgets with simple lifetime
>
> requirements with unique_ptrs. If Widget decides which type of smart
>
> pointer must be used, I can’t do that any more—either Widget’s
>
> allocator returns a shared_ptr and forces me to pay the cost of
>
> reference counting even for Widgets whose lifetime doesn’t warrant it,
>
> or worse, it returns a unique_ptr and prohibits me from reference
>

For what it's worth, shared_ptr is move constructible from unique_ptr.


> counting even when I want to. The caller knows best, IMO, how an object
>
> is going to be used and therefore which type of smart pointer is the
>
> right choice.
>
> --
>
> 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 11:26:19