weak_ptr doc problem

The weak_ptr docs says this: weak_ptr(); Effects: Constructs an **empty** weak_ptr. Postconditions: use_count() == 0. long use_count() const; Returns: if *this is **empty**, an unspecified nonnegative value; otherwise, the number of shared_ptr objects that share ownership with *this. use_count() seems underspecified and contradicts weak_ptr(). It should return exactly 0 when *this is empty. -- Daniel Wallin

Daniel Wallin wrote:
The weak_ptr docs says this:
weak_ptr();
Effects: Constructs an **empty** weak_ptr. Postconditions: use_count() == 0.
long use_count() const;
Returns: if *this is **empty**, an unspecified nonnegative value; otherwise, the number of shared_ptr objects that share ownership with *this.
use_count() seems underspecified and contradicts weak_ptr(). It should return exactly 0 when *this is empty.
Yes, use_count() is underspecified because the Technical Report now requires use_count() to be zero for all empty pointers. The documentation hasn't been updated yet to reflect that. [ That aside, it does not contradict weak_ptr(). The 'unspecified value' comes from empty weak pointers created from empty shared pointers, not from the default constructor. :-) ]
participants (2)
-
Daniel Wallin
-
Peter Dimov