Re: shared_ptr from auto_ptr in draft
On Oct 10, 10:50 pm, Daniel Kr?gler <daniel.krueg...@googlemail.com>
wrote:
On 10 Okt., 18:42, AlbertoBarb...@libero.it (Alberto Ganesh Barbati)
wrote:
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.
Shouldn't MoveConstructible be enough? And that is required.
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);
And of course, all these constructors should be rvalue-only.
Yechezkel Mett
---
[ 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 ]