```
optional<T>& operator=(nullopt_t) noexcept;
```

```
optional<T>& operator=(const optional& rhs);
```

Table 35 — optional::operator=(const optional&) effects

*this contains a value | *this does not contain a value | |

rhs contains a value | assigns *rhs to the contained value | initializes the contained value as if direct-non-list-initializing an object of type T with *rhs |

rhs does not contain a value | destroys the contained value by calling val->T::~T() | no effect |

If an exception is thrown during the call to T's copy constructor, no effect.

If an exception is thrown during the call to T's copy assignment,
the state of its contained value is as defined by the exception safety guarantee of T's copy assignment.

This operator shall be defined as deleted unless
is_copy_constructible_v<T> is true and
is_copy_assignable_v<T> is true.

```
optional<T>& operator=(optional&& rhs) noexcept(see below);
```

The result of the expression bool(rhs) remains unchanged.

Table 36 — optional::operator=(optional&&) effects

*this contains a value | *this does not contain a value | |

rhs contains a value | assigns std::move(*rhs) to the contained value | initializes the contained value as if direct-non-list-initializing an object of type T with std::move(*rhs) |

rhs does not contain a value | destroys the contained value by calling val->T::~T() | no effect |

Remarks:
The expression inside noexcept is equivalent to:

is_nothrow_move_assignable_v<T> && is_nothrow_move_constructible_v<T>

If any exception is thrown, the result of the expression bool(*this) remains unchanged.

If an exception is thrown during the call to T's move constructor,
the state of *rhs.val is determined by the exception safety guarantee of T's move constructor.

If an exception is thrown during the call to T's move assignment,
the state of *val and *rhs.val is determined by the exception safety guarantee of T's move assignment.

This operator shall not participate in overload resolution unless
is_move_constructible_v<T> is true and
is_move_assignable_v<T> is true.

```
template <class U = T> optional<T>& operator=(U&& v);
```

If an exception is thrown during the call to T's constructor, the state of v is determined by the exception safety guarantee of T's constructor.

If an exception is thrown during the call to T's assignment, the state of *val and v is determined by the exception safety guarantee of T's assignment.

This function shall not participate in overload resolution unless
is_same_v<optional<T>, decay_t<U>> is false,
conjunction_v<is_scalar<T>, is_same<T, decay_t<U>>> is false,
is_constructible_v<T, U> is true, and
is_assignable_v<T&, U> is true.

```
template <class U> optional<T>& operator=(const optional<U>& rhs);
```

Table 37 — optional::operator=(const optional<U>&) effects

*this contains a value | *this does not contain a value | |

rhs contains a value | assigns *rhs to the contained value | initializes the contained value as if direct-non-list-initializing
an object of type T with *rhs |

rhs does not contain a value | destroys the contained value by calling val->T::~T() | no effect |

If an exception is thrown during the call to T's constructor,
the state of *rhs.val is determined by
the exception safety guarantee of T's constructor.

If an exception is thrown during the call to T's assignment,
the state of *val and *rhs.val is determined by
the exception safety guarantee of T's assignment.

This function shall not participate in overload resolution unless

- is_constructible_v<T, const U&> is true,
- is_assignable_v<T&, const U&> is true,
- is_constructible_v<T, optional<U>&> is false,
- is_constructible_v<T, optional<U>&&> is false,
- is_constructible_v<T, const optional<U>&> is false,
- is_constructible_v<T, const optional<U>&&> is false,
- is_convertible_v<optional<U>&, T> is false,
- is_convertible_v<optional<U>&&, T> is false,
- is_convertible_v<const optional<U>&, T> is false,
- is_convertible_v<const optional<U>&&, T> is false,
- is_assignable_v<T&, optional<U>&> is false,
- is_assignable_v<T&, optional<U>&&> is false,
- is_assignable_v<T&, const optional<U>&> is false, and

```
template <class U> optional<T>& operator=(optional<U>&& rhs);
```

The result of the expression bool(rhs) remains unchanged.

Table 38 — optional::operator=(optional<U>&&) effects

*this contains a value | *this does not contain a value | |

rhs contains a value | assigns std::move(*rhs) to the contained value | initializes the contained value as if direct-non-list-initializing
an object of type T with std::move(*rhs) |

rhs does not contain a value | destroys the contained value by calling val->T::~T() | no effect |

If an exception is thrown during the call to T's constructor,
the state of *rhs.val is determined by
the exception safety guarantee of T's constructor.

If an exception is thrown during the call to T's assignment,
the state of *val and *rhs.val is determined by
the exception safety guarantee of T's assignment.

This function shall not participate in overload resolution unless

- is_constructible_v<T, U> is true,
- is_assignable_v<T&, U> is true,
- is_constructible_v<T, optional<U>&> is false,
- is_constructible_v<T, optional<U>&&> is false,
- is_constructible_v<T, const optional<U>&> is false,
- is_constructible_v<T, const optional<U>&&> is false,
- is_convertible_v<optional<U>&, T> is false,
- is_convertible_v<optional<U>&&, T> is false,
- is_convertible_v<const optional<U>&, T> is false,
- is_convertible_v<const optional<U>&&, T> is false,
- is_assignable_v<T&, optional<U>&> is false,
- is_assignable_v<T&, optional<U>&&> is false,
- is_assignable_v<T&, const optional<U>&> is false, and

```
template <class... Args> T& emplace(Args&&... args);
```

```
template <class U, class... Args> T& emplace(initializer_list<U> il, Args&&... args);
```