| 362 | } |
| 363 | |
| 364 | void swap(optional& rhs) noexcept { |
| 365 | if (_engaged && rhs._engaged) { |
| 366 | std::swap(**this, *rhs); |
| 367 | } else if (_engaged) { |
| 368 | rhs = std::move(*this); |
| 369 | reset(); |
| 370 | } else if (rhs._engaged) { |
| 371 | *this = std::move(rhs); |
| 372 | rhs.reset(); |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | // Destroys any contained value if the `optional` is not empty. |
| 377 | void reset() { |