[unique.ptr.single.asgn]

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

## 20.3 Smart pointers [[smartptr]](smartptr#unique.ptr.single.asgn)

### 20.3.1 Unique-ownership pointers [[unique.ptr]](unique.ptr#single.asgn)

#### 20.3.1.3 unique_ptr for single objects [[unique.ptr.single]](unique.ptr.single#asgn)

#### 20.3.1.3.4 Assignment [unique.ptr.single.asgn]

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

`constexpr unique_ptr& operator=(unique_ptr&& u) noexcept;
`

[1](#1)

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

*Constraints*: is_move_assignable_v<D> is true[.](#1.sentence-1)

[2](#2)

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

*Preconditions*: If D is not a reference type, D meets the[*Cpp17MoveAssignable*](utility.arg.requirements#:Cpp17MoveAssignable "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements (Table [33](utility.arg.requirements#tab:cpp17.moveassignable "Table 33: Cpp17MoveAssignable requirements")) and assignment
of the deleter from an rvalue of type D does not throw an exception[.](#2.sentence-1)

Otherwise, D is a reference type;remove_reference_t<D> meets the [*Cpp17CopyAssignable*](utility.arg.requirements#:Cpp17CopyAssignable "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements and assignment of the deleter from an
lvalue of type D does not throw an exception[.](#2.sentence-2)

[3](#3)

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

*Effects*: Calls reset(u.release()) followed byget_deleter() = std​::​forward<D>(u.get_deleter())[.](#3.sentence-1)

[4](#4)

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

*Postconditions*: If this != addressof(u),u.get() == nullptr,
otherwise u.get() is unchanged[.](#4.sentence-1)

[5](#5)

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

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

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

`template<class U, class E> constexpr unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
`

[6](#6)

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

*Constraints*: 

- [(6.1)](#6.1)

unique_ptr<U, E>​::​pointer is implicitly convertible to pointer, and

- [(6.2)](#6.2)

U is not an array type, and

- [(6.3)](#6.3)

is_assignable_v<D&, E&&> is true[.](#6.sentence-1)

[7](#7)

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

*Preconditions*: If E is not a reference type,
assignment of the deleter from an rvalue of type E is well-formed and does not throw an exception[.](#7.sentence-1)

Otherwise, E is a reference type and
assignment of the deleter from an lvalue of type E is well-formed and does not throw an exception[.](#7.sentence-2)

[8](#8)

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

*Effects*: Calls reset(u.release()) followed byget_deleter() = std​::​forward<E>(u.get_deleter())[.](#8.sentence-1)

[9](#9)

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

*Postconditions*: u.get() == nullptr[.](#9.sentence-1)

[10](#10)

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

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

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

`constexpr unique_ptr& operator=(nullptr_t) noexcept;
`

[11](#11)

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

*Effects*: As if by reset()[.](#11.sentence-1)

[12](#12)

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

*Postconditions*: get() == nullptr[.](#12.sentence-1)

[13](#13)

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

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