This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of CD1 status.

### 743. rvalue `swap` for `shared_ptr`

Section: 20.3.2.2.9 [util.smartptr.shared.spec] Status: CD1 Submitter: Howard Hinnant Opened: 2007-10-10 Last modified: 2016-01-28

Priority: Not Prioritized

View all issues with CD1 status.

Discussion:

When the LWG looked at 674 in Kona the following note was made:

> We may need to open an issue to deal with the question of whether `shared_ptr` needs an rvalue `swap`.

This issue was opened in response to that note.

I believe allowing rvalue `shared_ptr`s to `swap` is both appropriate, and consistent with how other library components are currently specified.

[ Bellevue: ]

> Concern that the three signatures for swap is needlessly complicated, but this issue merely brings shared_ptr into equal complexity with the rest of the library. Will open a new issue for concern about triplicate signatures.

> Adopt issue as written.

Proposed resolution:

Change the synopsis in 20.3.2.2 [util.smartptr.shared]:

>     void swap(shared_ptr&& r);
>     ...
>     template<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b);
>     template<class T> void swap(shared_ptr<T>&& a, shared_ptr<T>& b);
>     template<class T> void swap(shared_ptr<T>& a, shared_ptr<T>&& b);

Change 20.3.2.2.5 [util.smartptr.shared.mod]:

>     void swap(shared_ptr&& r);

Change 20.3.2.2.9 [util.smartptr.shared.spec]:

>     template<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b);
>     template<class T> void swap(shared_ptr<T>&& a, shared_ptr<T>& b);
>     template<class T> void swap(shared_ptr<T>& a, shared_ptr<T>&& b);