This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++14 status.
weak_ptr
should be movableSection: 20.3.2.3 [util.smartptr.weak] Status: C++14 Submitter: Stephan T. Lavavej Opened: 2013-09-21 Last modified: 2016-01-28
Priority: 2
View all other issues in [util.smartptr.weak].
View all issues with C++14 status.
Discussion:
Like shared_ptr
, weak_ptr
should be movable to avoid unnecessary atomic increments/decrements of the weak refcount.
[2014-02-13 Issaquah: Move to Immediate]
Proposed resolution:
This wording is relative to N3691.
Edit 20.3.2.3 [util.smartptr.weak]/1, class template weak_ptr
synopsis, as indicated:
namespace std { template<class T> class weak_ptr { public: typedef T element_type; // 20.9.2.3.1, constructors constexpr weak_ptr() noexcept; template<class Y> weak_ptr(shared_ptr<Y> const& r) noexcept; weak_ptr(weak_ptr const& r) noexcept; template<class Y> weak_ptr(weak_ptr<Y> const& r) noexcept; weak_ptr(weak_ptr&& r) noexcept; template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept; […] // 20.9.2.3.3, assignment weak_ptr& operator=(weak_ptr const& r) noexcept; template<class Y> weak_ptr& operator=(weak_ptr<Y> const& r) noexcept; template<class Y> weak_ptr& operator=(shared_ptr<Y> const& r) noexcept; weak_ptr& operator=(weak_ptr&& r) noexcept; template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept; }; }
Add the following new paragraphs at the end of sub-clause 20.3.2.3.2 [util.smartptr.weak.const]:
weak_ptr(weak_ptr&& r) noexcept; template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept;-?- Remark: The second constructor shall not participate in overload resolution unless
-?- Effects: Move-constructs aY*
is implicitly convertible toT*
.weak_ptr
instance fromr
. -?- Postconditions:*this
shall contain the old value ofr
.r
shall be empty.r.use_count() == 0
.
Edit 20.3.2.3.4 [util.smartptr.weak.assign] as indicated:
weak_ptr& operator=(const weak_ptr& r) noexcept; template<class Y> weak_ptr& operator=(const weak_ptr<Y>& r) noexcept; template<class Y> weak_ptr& operator=(const shared_ptr<Y>& r) noexcept;-1- Effects: […]
-2- Remarks: […] -?- Returns:*this
.
weak_ptr& operator=(weak_ptr&& r) noexcept; template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept;-?- Effects: Equivalent to
-?- Returns:weak_ptr(std::move(r)).swap(*this)
.*this
.