|
| | StatusOr () |
| | Constructs a StatusOr object that contains a non-OK status. More...
|
| |
| | ~StatusOr () |
| |
| | StatusOr (const Status &status) |
| | Constructs a StatusOr object with the given non-OK Status object. More...
|
| |
| | StatusOr (const absl::Status &status) |
| | Constructs a StatusOr object with the given non-OK absl::Status object. More...
|
| |
| template<typename U , typename E = typename std::enable_if< is_implicitly_constructible<T, U>::value && !std::is_same<typename std::remove_reference< typename std::remove_cv<U>::type>::type, Status>::value && !std::is_same<typename std::remove_reference< typename std::remove_cv<U>::type>::type, absl::Status>::value>::type> |
| | StatusOr (U &&value) |
| | Constructs a StatusOr object that contains value. More...
|
| |
| | StatusOr (const StatusOr &other) |
| | Copy constructor. More...
|
| |
| template<typename U , typename E = typename std::enable_if< is_implicitly_constructible<T, const U &>::value>::type> |
| | StatusOr (const StatusOr< U > &other) |
| | Templatized constructor that constructs a StatusOr<T> from a const reference to a StatusOr<U>. More...
|
| |
| template<typename U , typename E = typename std::enable_if< is_implicitly_constructible<T, const U &>::value>::type> |
| | StatusOr (const absl::StatusOr< U > &other) |
| | Templatized constructor that constructs a StatusOr<T> from a const reference to an absl::StatusOr<U>. More...
|
| |
| StatusOr & | operator= (const StatusOr &other) |
| | Copy-assignment operator. More...
|
| |
| template<typename U , typename E = typename std::enable_if< is_implicitly_constructible<T, U &&>::value>::type> |
| | StatusOr (StatusOr< U > &&other) |
| | Templatized constructor which constructs a StatusOr<T> by moving the contents of a StatusOr<U>. More...
|
| |
| template<typename U , typename E = typename std::enable_if< is_implicitly_constructible<T, U &&>::value>::type> |
| | StatusOr (absl::StatusOr< U > &&other) |
| | Templatized constructor which constructs a StatusOr<T> by moving the contents of an absl::StatusOr<U>. More...
|
| |
| StatusOr & | operator= (StatusOr &&other) |
| | Move-assignment operator. More...
|
| |
| template<typename U , typename E = typename std::enable_if< is_implicitly_constructible<U, T &&>::value>::type> |
| | operator absl::StatusOr< U > () const |
| |
| bool | ok () const |
| | Indicates whether the object contains a T value. More...
|
| |
| Status | status () const |
| | Gets the stored status object, or an OK status if a T value is stored. More...
|
| |
| const T & | value () const & |
| | Gets the stored T value. More...
|
| |
| T & | value () & |
| | Gets the stored T value. More...
|
| |
| T | value () && |
| | Moves and returns the internally-stored T value. More...
|
| |
| | ABSL_DEPRECATED ("Deprecated as part of Asylo's absl::Status migration. Use value(), " "operator*(), or operator->() instead.") const T &ValueOrDie() const & |
| | Gets the stored T value. More...
|
| |
| | ABSL_DEPRECATED ("Deprecated as part of Asylo's absl::Status migration. Use value(), " "operator*(), or operator->() instead.") T &ValueOrDie() & |
| | Gets a mutable reference to the stored T value. More...
|
| |
| | ABSL_DEPRECATED ("Deprecated as part of Asylo's absl::Status migration. Use value(), " "operator*(), or operator->() instead.") T ValueOrDie() && |
| | Moves and returns the internally-stored T value. More...
|
| |
| const T & | operator* () const & |
| | Gets the stored T value. More...
|
| |
| T & | operator* () & |
| | Gets the stored T value. More...
|
| |
| T | operator* () && |
| | Gets the stored T value. More...
|
| |
| const T * | operator-> () const |
| | Aecceses the stored T value. More...
|
| |
| T * | operator-> () |
| | Gets the stored T value. More...
|
| |
template<class T>
class asylo::StatusOr< T >
A class for representing either a usable value, or an error.
A StatusOr object either contains a value of type T or a Status object explaining why such a value is not present. The type T must be copy-constructible and/or move-constructible.
The state of a StatusOr object may be determined by calling ok() or status(). The ok() method returns true if the object contains a valid value. The status() method returns the internal Status object. A StatusOr object that contains a valid value will return an OK Status for a call to status().
A value of type T may be extracted by dereferencing an OK StatusOr object, either with operator*() or operator->(). These operators should only be called if a call to ok() returns true. Sample usage:
Foo foo = *result;
foo.DoSomethingCool();
} else {
}
Or more concisely:
result->DoSomethingCool();
} else {
}
If T is a move-only type, like std::unique_ptr<>, then the value should only be extracted after invoking std::move() on the StatusOr object. Sample usage:
std::unique_ptr<Foo> foo = *std::move(result);
foo->DoSomethingCool();
} else {
}
If exceptions are enabled, callers can alternatively use the value() method to extract the contents of a StatusOr. Calls to value() throw absl::BadStatusOrAccess if the StatusOr is not OK. Sample usage:
try {
result.
value().DoSomethingCool();
} catch (const absl::BadStatusOrAccess &bad_access) {
}
If exceptions are disabled, then calls to value() on a non-OK StatusOr will abort the program.
StatusOr is provided for the convenience of implementing functions that return some value but may fail during execution. For instance, consider a function with the following signature:
This function may instead be written as:
template<class T>
template<typename U , typename E = typename std::enable_if< is_implicitly_constructible<T, U>::value && !std::is_same<typename std::remove_reference< typename std::remove_cv<U>::type>::type, Status>::value && !std::is_same<typename std::remove_reference< typename std::remove_cv<U>::type>::type, absl::Status>::value>::type>
Constructs a StatusOr object that contains value.
The resulting object is considered to have an OK status. The wrapped element can be accessed by dereferencing or with value().
This constructor is made implicit so that a function with a return type of StatusOr<T> can return an object of type U &&, implicitly converting it to a StatusOr<T> object.
Note that T must be implicitly constructible from U, and U must not be a (cv-qualified) Status or Status-reference type. Due to C++ reference-collapsing rules and perfect-forwarding semantics, this constructor matches invocations that pass value either as a const reference or as an rvalue reference. Since StatusOr needs to work for both reference and rvalue-reference types, the constructor uses perfect forwarding to avoid invalidating arguments that were passed by reference. See http://thbecker.net/articles/rvalue_references/section_08.html for additional details.
- Parameters
-
| value | The value to initialize to. |