On Thu, 17 Sep 2020 at 18:18, Christopher Head via Std-Discussion <std-discussion@lists.isocpp.org> wrote:
On Thu, 17 Sep 2020 13:56:28 +0430

Farid Mehrabi via Std-Discussion <std-discussion@lists.isocpp.org>

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@lists.isocpp.org

https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion

--
Richard Hodges
hodges.r@gmail.com
office: +442032898513
home: +376841522
mobile: +376380212