Re: [Defect Report] shared_ptr and nullptr
Joe Gottman ha scritto:
Proposed Resolution:
Add the following constructors to 20.6.6.2:
explicit shared_ptr(nullptr_t);
I believe that there is value in allowing this constructor for implicit
conversion. If it is explicit, it isn't very useful, IMHO. Why would one
prefer to write shared_ptr<SomeType>(nullptr) instead of the more
concise shared_ptr<SomeType>() or:
shared_ptr<SomeType> ptr(nullptr);
instead of simply:
shared_ptr<SomeType> ptr;
?
Moreover, I find it nice to be able to write:
void foo(const shared_ptr<SomeType>& ptr);
int bar()
{
foo(nullptr);
}
without explicitly writing the conversion. The main reason for having
the constructor explicit is to avoid the shared_ptr take the ownership
of a regular pointer by mistake. However, in the case of a nullptr_t
there is no such danger.
If my argument has value, we may think of adding a similar non-explicit
constructor to unique_ptr<> as well.
template <class D> shared_ptr(nullptr_t, D d, A a);
template <class D, class A> shared_ptr(nullptr_t, D d, A a);
I assume there is a typo in the first one: "A a" should not be present.
Just my two eurocent,
Ganesh
---
[ 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 ]