| 592 | } |
| 593 | |
| 594 | void swap(optional& rhs) noexcept(std::is_nothrow_move_constructible<T>::value && |
| 595 | dlib::is_nothrow_swappable<T>::value) |
| 596 | { |
| 597 | using std::swap; |
| 598 | |
| 599 | if (*this && rhs) |
| 600 | { |
| 601 | swap(**this, *rhs); |
| 602 | } |
| 603 | |
| 604 | else if (*this && !rhs) |
| 605 | { |
| 606 | rhs = std::move(**this); |
| 607 | reset(); |
| 608 | } |
| 609 | |
| 610 | else if (!*this && rhs) |
| 611 | { |
| 612 | *this = std::move(*rhs); |
| 613 | rhs.reset(); |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | constexpr const T* operator->() const noexcept { return &this->val; } |
| 618 | constexpr T* operator->() noexcept { return &this->val; } |