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 <type_traits> 84 class StatusOr final {
108 google::
cloud::internal::ThrowInvalidArgument(
__func__);
112 StatusOr(StatusOr&& rhs) : status_(std::move(rhs.status_)) {
114 new (&value_) T(std::move(*rhs));
124 status_ = std::move(rhs.status_);
127 new (&value_) T(std::move(*rhs));
133 status_ = std::move(rhs.status_);
136 **
this = *std::move(rhs);
141 StatusOr(StatusOr
const& rhs) : status_(rhs.status_) {
143 new (&value_) T(*rhs);
153 status_ = rhs.status_;
156 new (&value_) T(*rhs);
157 status_ = rhs.status_;
162 status_ = rhs.status_;
166 status_ = rhs.status_;
182 template <
typename U = T>
183 typename std::enable_if<
184 not std::is_same<StatusOr,
typename std::decay<U>::type>::value,
191 new (&value_) T(std::forward<U>(rhs));
195 **
this = std::forward<U>(rhs);
211 StatusOr(T&& rhs) : status_
() {
new (&value_) T(std::move(rhs)); }
235 #if GOOGLE_CLOUD_CPP_HAVE_CONST_REF_REF
236 T
const&& operator*()
const&& {
return std::move(value_); }
277 return std::move(**
this);
280 #if GOOGLE_CLOUD_CPP_HAVE_CONST_REF_REF
281 T
const&& value()
const&& {
283 return std::move(**
this);
299 #if GOOGLE_CLOUD_CPP_HAVE_CONST_REF_REF
300 Status const&& status()
const&& {
return std::move(status_); }
305 void CheckHasValue()
const& {
307 internal::ThrowStatus(status_);
312 void CheckHasValue() && {
314 internal::ThrowStatus(std::move(status_));
324 template <
typename T>
326 return StatusOr<T>(std::move(rhs));
T const & value() const &
StatusOr()
Initializes with an error status (UNKNOWN).
#define GOOGLE_CLOUD_CPP_NS
Reports error code and details from a remote request.
Contains all the Google Cloud C++ Library APIs.
StatusOr(T &&rhs)
Creates a new StatusOr<T> holding the value rhs.
StatusOr(Status rhs)
Creates a new StatusOr<T> holding the error condition rhs.
StatusOr< T > make_status_or(T rhs)
std::enable_if< not std::is_same< StatusOr, typename std::decay< U >::type >::value, StatusOr >::type & operator=(U &&rhs)
Assign a T (or anything convertible to T) into the StatusOr.
T const * operator->() const &
Status(StatusCode status_code, std::string message)
Status const & status() const &
StatusOr(StatusOr const &rhs)
StatusOr & operator=(StatusOr &&rhs)
StatusOr & operator=(StatusOr const &rhs)
T const & operator*() const &
StatusCode
Well-known status codes with grpc::StatusCode-compatible values.