[util.smartptr.weak.const]

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

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

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

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

#### 20.3.2.3.2 Constructors [util.smartptr.weak.const]

[ð](#lib:weak_ptr,constructor)

`constexpr weak_ptr() noexcept;
`

[1](#1)

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

*Effects*: Constructs an empty weak_ptr object that stores a null pointer value[.](#1.sentence-1)

[2](#2)

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

*Postconditions*: use_count() == 0[.](#2.sentence-1)

[ð](#lib:weak_ptr,constructor_)

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

[3](#3)

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

*Constraints*: For the second and third constructors, Y* is compatible with T*[.](#3.sentence-1)

[4](#4)

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

*Effects*: If r is empty, constructs
an empty weak_ptr object that stores a null pointer value;
otherwise, constructs
a weak_ptr object that shares ownership
with r and stores a copy of the pointer stored in r[.](#4.sentence-1)

[5](#5)

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

*Postconditions*: use_count() == r.use_count()[.](#5.sentence-1)

[ð](#lib:weak_ptr,constructor__)

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

[6](#6)

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

*Constraints*: For the second constructor, Y* is compatible with T*[.](#6.sentence-1)

[7](#7)

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

*Effects*: Move constructs a weak_ptr instance from r[.](#7.sentence-1)

[8](#8)

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

*Postconditions*: *this contains the old value of r[.](#8.sentence-1)

r is empty, stores a null pointer value, and r.use_count() == 0[.](#8.sentence-2)
