Re: [Defect Report] shared_ptr and nullptr
Just a couple more remarks:
Joe Gottman ha scritto:
template <class D> shared_ptr(nullptr_t, D d);
template <class D, class A> shared_ptr<nullptr_t, D d, A a);
Requires: D shall be CopyConstructible. The copy constructor and
destructor of D shall not throw exceptions. The expression
d(nullptr) shall be well-formed, shall have well defined behavior,
and shall not throw exceptions. A shall be an allocator (20.1.2).
The copy constructor and destructor of A shall not throw
exceptions.
Effects: Constructs a shared_ptr object that owns deleter d. The
second constructor shall use a copy of a to allocate memory for
internal use.
Postconditions: use_count() == 1 and get() == nullptr.
Throws: bad_alloc, or an implementation-defined exception when a
resource other than memory could not be obtained.
Exception safety: If an exception is thrown, d(nullptr) is called.
1) As the value of the (null) pointer is going to be eventually
converted to type T*, the expression that is going to be called in the
destructor will be d((T*)nullptr) rather than d(nullptr). Therefore the
expression that must be well-formed and that shall be called if an
exception is thrown should follow accordingly. This would make a
difference, for example, with this deleter:
struct naive_deleter
{
template <class T>
void operator()(T* ptr) const { delete ptr; }
};
2) I actually like the "get() == nullptr" in the postcondition, but I
think we should keep a consistent style throughout all the clause. So
either we use the standard "get() == 0" here or we replace every "get()
== 0" to "get() == nullptr" all over the place. (For what it's worth, my
preference goes to the second option.)
Cheers,
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 ]