[util.smartptr.weak.assign]

# 20 Memory management library [[mem]](./#mem)

## 20.3 Smart pointers [[smartptr]](smartptr#util.smartptr.weak.assign)

### 20.3.2 Shared-ownership pointers [[util.sharedptr]](util.sharedptr#util.smartptr.weak.assign)

#### 20.3.2.3 Class template weak_ptr [[util.smartptr.weak]](util.smartptr.weak#assign)

#### 20.3.2.3.4 Assignment [util.smartptr.weak.assign]

[ð](#lib:operator=,weak_ptr)

`constexpr weak_ptr& operator=(const weak_ptr& r) noexcept;
template<class Y> constexpr weak_ptr& operator=(const weak_ptr<Y>& r) noexcept;
template<class Y> constexpr weak_ptr& operator=(const shared_ptr<Y>& r) noexcept;
`

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L4993)

*Effects*: Equivalent to weak_ptr(r).swap(*this)[.](#1.sentence-1)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L4997)

*Returns*: *this[.](#2.sentence-1)

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L5001)

*Remarks*: The implementation may meet the effects (and the
implied guarantees) via different means, without creating a temporary object[.](#3.sentence-1)

[ð](#lib:operator=,weak_ptr_)

`constexpr weak_ptr& operator=(weak_ptr&& r) noexcept;
template<class Y> constexpr weak_ptr& operator=(weak_ptr<Y>&& r) noexcept;
`

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L5014)

*Effects*: Equivalent to weak_ptr(std​::​move(r)).swap(*this)[.](#4.sentence-1)

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L5018)

*Returns*: *this[.](#5.sentence-1)
