- Result() { /* Nothing to do */}
- ~Result() { this->reset(); }
-
- // Copy (if T is copyable) and move:
- Result(Result const& that)
- {
- (*this) = that;
- }
- Result& operator=(Result const& that)
- {
- this->reset();
- switch (that.status_) {
- case ResultStatus::invalid:
- break;
- case ResultStatus::value:
- new (&value_) T(that.value);
- break;
- case ResultStatus::exception:
- new (&exception_) T(that.exception);
- break;
- default:
- THROW_IMPOSSIBLE;
- }
- return *this;
- }
- Result(Result&& that)
- {
- *this = std::move(that);
- }
- Result& operator=(Result&& that)
- {
- this->reset();
- switch (that.status_) {
- case ResultStatus::invalid:
- break;
- case ResultStatus::value:
- new (&value_) T(std::move(that.value));
- that.value.~T();
- break;
- case ResultStatus::exception:
- new (&exception_) T(std::move(that.exception));
- that.exception.~exception_ptr();
- break;
- default:
- THROW_IMPOSSIBLE;
- }
- that.status_ = ResultStatus::invalid;
- return *this;
- }
-