15 #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STATUS_OR_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STATUS_OR_H
18 #include "google/cloud/internal/throw_delegate.h"
19 #include "google/cloud/status.h"
20 #include "google/cloud/version.h"
21 #include "absl/types/optional.h"
22 #include <type_traits>
89 class StatusOr final {
107 : status_(std::move(other.status_)), value_(std::move(other.value_)) {
108 other.status_ = MakeDefaultStatus();
112 status_ = std::move(other.status_);
113 value_ = std::move(other.value_);
114 other.status_ = MakeDefaultStatus();
131 google::
cloud::internal::ThrowInvalidArgument(
__func__);
142 *
this = StatusOr(std::move(status));
152 template <
typename U = T>
153 typename std::enable_if<
154 !std::is_same<StatusOr,
typename std::decay<U>::type>::value,
158 value_ = std::forward<U>(rhs);
197 T
const&&
operator*()
const&& {
return *std::move(value_); }
237 return std::move(**
this);
242 return std::move(**
this);
257 static Status MakeDefaultStatus() {
261 void CheckHasValue()
const& {
263 internal::ThrowStatus(status_);
268 void CheckHasValue() && {
270 internal::ThrowStatus(std::move(status_));
275 absl::optional<T> value_;
280 template <
typename T>
281 bool operator==(StatusOr<T>
const& a, StatusOr<T>
const& b) {
282 if (!a || !b)
return a.status() == b.status();
288 template <
typename T>
289 bool operator!=(StatusOr<T>
const& a, StatusOr<T>
const& b) {
293 template <
typename T>
295 return StatusOr<T>(std::move(rhs));