| 47 | // TraitsBase specialization. |
| 48 | template <typename T> |
| 49 | class StatusOrData { |
| 50 | template <typename U> |
| 51 | friend class StatusOrData; |
| 52 | |
| 53 | public: |
| 54 | StatusOrData() = delete; |
| 55 | |
| 56 | StatusOrData(const StatusOrData& other) { |
| 57 | if (other.ok()) { |
| 58 | MakeValue(other.data_); |
| 59 | MakeStatus(); |
| 60 | } else { |
| 61 | MakeStatus(other.status_); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | StatusOrData(StatusOrData&& other) noexcept { |
| 66 | if (other.ok()) { |
| 67 | MakeValue(std::move(other.data_)); |
| 68 | MakeStatus(); |
| 69 | } else { |
| 70 | MakeStatus(std::move(other.status_)); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | template <typename U> |
| 75 | StatusOrData(const StatusOrData<U>& other) { |
| 76 | if (other.ok()) { |
| 77 | MakeValue(other.data_); |
| 78 | MakeStatus(); |
| 79 | } else { |
| 80 | MakeStatus(other.status_); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | template <typename U> |
| 85 | StatusOrData(StatusOrData<U>&& other) { |
| 86 | if (other.ok()) { |
| 87 | MakeValue(std::move(other.data_)); |
| 88 | MakeStatus(); |
| 89 | } else { |
| 90 | MakeStatus(std::move(other.status_)); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | explicit StatusOrData(const T& value) : data_(value) { MakeStatus(); } |
| 95 | explicit StatusOrData(T&& value) : data_(std::move(value)) { MakeStatus(); } |
| 96 | |
| 97 | explicit StatusOrData(const Status& status) : status_(status) { |
| 98 | EnsureNotOk(); |
| 99 | } |
| 100 | explicit StatusOrData(Status&& status) : status_(std::move(status)) { |
| 101 | EnsureNotOk(); |
| 102 | } |
| 103 | |
| 104 | StatusOrData& operator=(const StatusOrData& other) { |
| 105 | if (this == &other) return *this; |
| 106 | if (other.ok()) |