Swaps this optional with the other. If neither optionals have a value, nothing happens. If both have a value, the values are swapped. If one has a value, it is moved to the other and the movee is left valueless.
| 4695 | /// If one has a value, it is moved to the other and the movee is left |
| 4696 | /// valueless. |
| 4697 | void swap(optional& rhs) noexcept(std::is_nothrow_move_constructible<T>::value&& detail::is_nothrow_swappable<T>::value) { |
| 4698 | if (has_value()) { |
| 4699 | if (rhs.has_value()) { |
| 4700 | using std::swap; |
| 4701 | swap(**this, *rhs); |
| 4702 | } |
| 4703 | else { |
| 4704 | new (std::addressof(rhs.m_value)) T(std::move(this->m_value)); |
| 4705 | this->m_value.T::~T(); |
| 4706 | } |
| 4707 | } |
| 4708 | else if (rhs.has_value()) { |
| 4709 | new (std::addressof(this->m_value)) T(std::move(rhs.m_value)); |
| 4710 | rhs.m_value.T::~T(); |
| 4711 | } |
| 4712 | } |
| 4713 | |
| 4714 | /// \returns a pointer to the stored value |
| 4715 | /// \requires a value is stored |