674. shared_ptr interface changes for consistency with N1856

Section: 23.11.3 [util.smartptr.shared] Status: CD1 Submitter: Peter Dimov Opened: 2007-05-05 Last modified: 2016-02-10

Priority: Not Prioritized

View other active issues in [util.smartptr.shared].

View all other issues in [util.smartptr.shared].

View all issues with CD1 status.

Discussion:

N1856 does not propose any changes to shared_ptr. It needs to be updated to use a rvalue reference where appropriate and to interoperate with unique_ptr as it does with auto_ptr.

Proposed resolution:

Change 23.11.3 [util.smartptr.shared] as follows:

template<class Y> explicit shared_ptr(auto_ptr<Y>&&& r);
template<class Y, class D> explicit shared_ptr(const unique_ptr<Y,D>& r) = delete;
template<class Y, class D> explicit shared_ptr(unique_ptr<Y,D>&& r);
...
template<class Y> shared_ptr& operator=(auto_ptr<Y>&&& r);
template<class Y, class D> shared_ptr& operator=(const unique_ptr<Y,D>& r) = delete;
template<class Y, class D> shared_ptr& operator=(unique_ptr<Y,D>&& r);

Change 23.11.3.1 [util.smartptr.shared.const] as follows:

template<class Y> shared_ptr(auto_ptr<Y>&&& r);

Add to 23.11.3.1 [util.smartptr.shared.const]:

template<class Y, class D> shared_ptr(unique_ptr<Y, D>&& r);

Effects: Equivalent to shared_ptr( r.release(), r.get_deleter() ) when D is not a reference type, shared_ptr( r.release(), ref( r.get_deleter() ) ) otherwise.

Exception safety: If an exception is thrown, the constructor has no effect.

Change 23.11.3.3 [util.smartptr.shared.assign] as follows:

template<class Y> shared_ptr& operator=(auto_ptr<Y>&&& r);

Add to 23.11.3.3 [util.smartptr.shared.assign]:

template<class Y, class D> shared_ptr& operator=(unique_ptr<Y,D>&& r);

-4- Effects: Equivalent to shared_ptr(std::move(r)).swap(*this).

-5- Returns: *this.

[ Kona (2007): We may need to open an issue (743) to deal with the question of whether shared_ptr needs an rvalue swap. ]