C++ Logo


Advanced search

Subject: Re: Making the new expression smart
From: Christopher Head (chead_at_[hidden])
Date: 2020-09-17 11:17:50

On Thu, 17 Sep 2020 13:56:28 +0430
Farid Mehrabi via Std-Discussion <std-discussion_at_[hidden]>

> 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
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 list run by std-discussion-owner@lists.isocpp.org

Older Archives on Google Groups