Title
weak_ptr should be movable
Status
c++14
Section
[util.smartptr.weak]
Submitter
Stephan T. Lavavej

Created on 2013-09-21.00:00:00 last changed 130 months ago

Messages

Date: 2014-02-14.07:07:05

Proposed resolution:

This wording is relative to N3691.

  1. Edit [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;
      };
    }
    
  2. Add the following new paragraphs at the end of sub-clause [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 Y* is implicitly convertible to T*.

    -?- Effects: Move-constructs a weak_ptr instance from r.

    -?- Postconditions: *this shall contain the old value of r. r shall be empty. r.use_count() == 0.

  3. Edit [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 weak_ptr(std::move(r)).swap(*this).

    -?- Returns: *this.

Date: 2014-02-13.00:00:00

[ 2014-02-13 Issaquah: Move to Immediate ]

Date: 2013-09-21.00:00:00

Like shared_ptr, weak_ptr should be movable to avoid unnecessary atomic increments/decrements of the weak refcount.

History
Date User Action Args
2014-02-27 17:03:20adminsetstatus: wp -> c++14
2014-02-20 13:52:38adminsetstatus: immediate -> wp
2014-02-14 07:07:05adminsetmessages: + msg6854
2014-02-14 07:07:05adminsetstatus: new -> immediate
2013-10-11 17:45:06adminsetmessages: + msg6699
2013-09-21 00:00:00admincreate