Re: shared_ptr from auto_ptr in draft
On 10 Okt., 18:42, AlbertoBarb...@libero.it (Alberto Ganesh Barbati)
wrote:
I note that the draft (n2369) has shared_ptr constructors which take
auto_ptr. Since auto_ptr has been deprecated, shouldn't these be
changed to take unique_ptr?
Even if auto_ptr has been deprecated, I don't think the constructor with
the auto_ptr should be removed. However, I agree that adding a new
constructor that takes a unique_ptr is definetely a good idea,
especially because such constructor should take the unique_ptr deleter
into consideration. For example, if u is a unique pointer, then
shared_ptr p(u);
should be equivalent to:
shared_ptr p(u.release(), u.get_deleter());
without a dedicated constructor, it would be too easy to forget the
u.get_deleter() part.
I agree with your proposal to add a corresponding shared_ptr
c'tor accepting a unique_ptr with the above described semantic,
although there might exist one quirk and that is the point that
unique_ptr's deleter is not required to be CopyConstructible.
Of-course, we could simply wait for a nastily choking compiler
at this point;-)
What I really do not understand is that there exists no c'tor
template<class Y> explicit unique_ptr(auto_ptr<Y>& r);
which is astonishing, because unique_ptr is actually
the proposed replacement for auto_ptr. This c'tor seems
IMO more natural than the current one to shared_ptr:
template<class Y> explicit shared_ptr(auto_ptr<Y>& r);
Greetings,
Daniel
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]