template <typename T>
class StatusOr
Defined at line 192 of file ../../third_party/abseil-cpp/absl/status/statusor.h
TODO(b/176172494): ABSL_MUST_USE_RESULT should expand to the more strict
[[nodiscard]]. For now, just use [[nodiscard]] directly when it is available.
Public Methods
void StatusOr<T> (const StatusOr<T> & )
`StatusOr
<T
>` is copy constructible if `T` is copy constructible.
Defined at line 220 of file ../../third_party/abseil-cpp/absl/status/statusor.h
StatusOr<T> & operator= (const StatusOr<T> & )
`StatusOr
<T
>` is copy assignable if `T` is copy constructible and copy
assignable.
Defined at line 223 of file ../../third_party/abseil-cpp/absl/status/statusor.h
void StatusOr<T> (StatusOr<T> && )
`StatusOr
<T
>` is move constructible if `T` is move constructible.
Defined at line 226 of file ../../third_party/abseil-cpp/absl/status/statusor.h
StatusOr<T> & operator= (StatusOr<T> && )
`StatusOr
<T
>` is moveAssignable if `T` is move constructible and move
assignable.
Defined at line 229 of file ../../third_party/abseil-cpp/absl/status/statusor.h
template <typename U, absl::enable_if_t<
absl::conjunction<
absl::negation<std::is_same<T, U>>,
std::is_constructible<T, const U&>,
std::is_convertible<const U&, T>,
absl::negation<
internal_statusor::IsConstructibleOrConvertibleFromStatusOr<
T, U>>>::value,
int> = 0>
void StatusOr<T> (const StatusOr<U> & other)
Constructs a new `absl::StatusOr
<T
>` from an `absl::StatusOr
<U
>`, when `T`
is constructible from `U`. To avoid ambiguity, these constructors are
disabled if `T` is also constructible from `StatusOr
<U
>.`. This constructor
is explicit if and only if the corresponding construction of `T` from `U`
is explicit. (This constructor inherits its explicitness from the
underlying constructor.)
Defined at line 250 of file ../../third_party/abseil-cpp/absl/status/statusor.h
template <typename U, absl::enable_if_t<
absl::conjunction<
absl::negation<std::is_same<T, U>>,
std::is_constructible<T, const U&>,
absl::negation<std::is_convertible<const U&, T>>,
absl::negation<
internal_statusor::IsConstructibleOrConvertibleFromStatusOr<
T, U>>>::value,
int> = 0>
void StatusOr<T> (const StatusOr<U> & other)
Defined at line 263 of file ../../third_party/abseil-cpp/absl/status/statusor.h
template <typename U, absl::enable_if_t<
absl::conjunction<
absl::negation<std::is_same<T, U>>, std::is_constructible<T, U&&>,
std::is_convertible<U&&, T>,
absl::negation<
internal_statusor::IsConstructibleOrConvertibleFromStatusOr<
T, U>>>::value,
int> = 0>
void StatusOr<T> (StatusOr<U> && other)
Defined at line 276 of file ../../third_party/abseil-cpp/absl/status/statusor.h
template <typename U, absl::enable_if_t<
absl::conjunction<
absl::negation<std::is_same<T, U>>, std::is_constructible<T, U&&>,
absl::negation<std::is_convertible<U&&, T>>,
absl::negation<
internal_statusor::IsConstructibleOrConvertibleFromStatusOr<
T, U>>>::value,
int> = 0>
void StatusOr<T> (StatusOr<U> && other)
Defined at line 288 of file ../../third_party/abseil-cpp/absl/status/statusor.h
template <typename U, absl::enable_if_t<
absl::conjunction<
absl::negation<std::is_same<T, U>>,
std::is_constructible<T, const U&>,
std::is_assignable<T, const U&>,
absl::negation<
internal_statusor::
IsConstructibleOrConvertibleOrAssignableFromStatusOr<
T, U>>>::value,
int> = 0>
StatusOr<T> & operator= (const StatusOr<U> & other)
Creates an `absl::StatusOr
<T
>` through assignment from an
`absl::StatusOr
<U
>` when:
* Both `absl::StatusOr
<T
>` and `absl::StatusOr
<U
>` are OK by assigning
`U` to `T` directly.
* `absl::StatusOr
<T
>` is OK and `absl::StatusOr
<U
>` contains an error
code by destroying `absl::StatusOr
<T
>`'s value and assigning from
`absl::StatusOr
<U
>'
* `absl::StatusOr
<T
>` contains an error code and `absl::StatusOr
<U
>` is
OK by directly initializing `T` from `U`.
* Both `absl::StatusOr
<T
>` and `absl::StatusOr
<U
>` contain an error
code by assigning the `Status` in `absl::StatusOr
<U
>` to
`absl::StatusOr
<T
>`
These overloads only apply if `absl::StatusOr
<T
>` is constructible and
assignable from `absl::StatusOr
<U
>` and `StatusOr
<T
>` cannot be directly
assigned from `StatusOr
<U
>`.
Defined at line 322 of file ../../third_party/abseil-cpp/absl/status/statusor.h
template <typename U, absl::enable_if_t<
absl::conjunction<
absl::negation<std::is_same<T, U>>, std::is_constructible<T, U&&>,
std::is_assignable<T, U&&>,
absl::negation<
internal_statusor::
IsConstructibleOrConvertibleOrAssignableFromStatusOr<
T, U>>>::value,
int> = 0>
StatusOr<T> & operator= (StatusOr<U> && other)
Defined at line 337 of file ../../third_party/abseil-cpp/absl/status/statusor.h
template <typename U = absl::Status, absl::enable_if_t<
absl::conjunction<
std::is_convertible<U&&, absl::Status>,
std::is_constructible<absl::Status, U&&>,
absl::negation<std::is_same<absl::decay_t<U>, absl::StatusOr<T>>>,
absl::negation<std::is_same<absl::decay_t<U>, T>>,
absl::negation<std::is_same<absl::decay_t<U>, absl::in_place_t>>,
absl::negation<internal_statusor::HasConversionOperatorToStatusOr<
T, U&&>>>::value,
int> = 0>
void StatusOr<T> (U && v)
Constructs a new `absl::StatusOr
<T
>` with a non-ok status. After calling
this constructor, `this->ok()` will be `false` and calls to `value()` will
crash, or produce an exception if exceptions are enabled.
The constructor also takes any type `U` that is convertible to
`absl::Status`. This constructor is explicit if an only if `U` is not of
type `absl::Status` and the conversion from `U` to `Status` is explicit.
REQUIRES: !Status(std::forward
<U
>(v)).ok(). This requirement is DCHECKed.
In optimized builds, passing absl::OkStatus() here will have the effect
of passing absl::StatusCode::kInternal as a fallback.
Defined at line 365 of file ../../third_party/abseil-cpp/absl/status/statusor.h
template <typename U = absl::Status, absl::enable_if_t<
absl::conjunction<
absl::negation<std::is_convertible<U&&, absl::Status>>,
std::is_constructible<absl::Status, U&&>,
absl::negation<std::is_same<absl::decay_t<U>, absl::StatusOr<T>>>,
absl::negation<std::is_same<absl::decay_t<U>, T>>,
absl::negation<std::is_same<absl::decay_t<U>, absl::in_place_t>>,
absl::negation<internal_statusor::HasConversionOperatorToStatusOr<
T, U&&>>>::value,
int> = 0>
void StatusOr<T> (U && v)
Defined at line 379 of file ../../third_party/abseil-cpp/absl/status/statusor.h
template <typename U = absl::Status, absl::enable_if_t<
absl::conjunction<
std::is_convertible<U&&, absl::Status>,
std::is_constructible<absl::Status, U&&>,
absl::negation<std::is_same<absl::decay_t<U>, absl::StatusOr<T>>>,
absl::negation<std::is_same<absl::decay_t<U>, T>>,
absl::negation<std::is_same<absl::decay_t<U>, absl::in_place_t>>,
absl::negation<internal_statusor::HasConversionOperatorToStatusOr<
T, U&&>>>::value,
int> = 0>
StatusOr<T> & operator= (U && v)
Defined at line 393 of file ../../third_party/abseil-cpp/absl/status/statusor.h
template <typename U = T, typename = typename std::enable_if<absl::conjunction<
std::is_constructible<T, U&&>, std::is_assignable<T&, U&&>,
absl::disjunction<
std::is_same<absl::remove_cvref_t<U>, T>,
absl::conjunction<
absl::negation<std::is_convertible<U&&, absl::Status>>,
absl::negation<internal_statusor::
HasConversionOperatorToStatusOr<T, U&&>>>>,
internal_statusor::IsForwardingAssignmentValid<T, U&&>>::value>::type>
StatusOr<T> & operator= (U && v)
If `*this` contains a `T` value before the call, the contained value is
assigned from `std::forward
<U
>(v)`; Otherwise, it is directly-initialized
from `std::forward
<U
>(v)`.
This function does not participate in overload unless:
1. `std::is_constructible_v
<T
, U>` is true,
2. `std::is_assignable_v
<T
&
, U>` is true.
3. `std::is_same_v
<StatusOr
<T
>, std::remove_cvref_t
<U
>>` is false.
4. Assigning `U` to `T` is not ambiguous:
If `U` is `StatusOr
<V
>` and `T` is constructible and assignable from
both `StatusOr
<V
>` and `V`, the assignment is considered bug-prone and
ambiguous thus will fail to compile. For example:
StatusOr
<bool
> s1 = true; // s1.ok()
&
&
*s1 == true
StatusOr
<bool
> s2 = false; // s2.ok()
&
&
*s2 == false
s1 = s2; // ambiguous, `s1 = *s2` or `s1 = bool(s2)`?
Defined at line 425 of file ../../third_party/abseil-cpp/absl/status/statusor.h
template <typename U = T, absl::enable_if_t<
absl::conjunction<
internal_statusor::IsDirectInitializationValid<T, U&&>,
std::is_constructible<T, U&&>, std::is_convertible<U&&, T>,
absl::disjunction<
std::is_same<absl::remove_cvref_t<U>, T>,
absl::conjunction<
absl::negation<std::is_convertible<U&&, absl::Status>>,
absl::negation<
internal_statusor::HasConversionOperatorToStatusOr<
T, U&&>>>>>::value,
int> = 0>
void StatusOr<T> (U && u)
Constructs the inner value `T` in-place using the provided args, using the
`T(U)` (direct-initialization) constructor. This constructor is only valid
if `T` can be constructed from a `U`. Can accept move or copy constructors.
This constructor is explicit if `U` is not convertible to `T`. To avoid
ambiguity, this constructor is disabled if `U` is a `StatusOr
<J
>`, where
`J` is convertible to `T`.
Defined at line 459 of file ../../third_party/abseil-cpp/absl/status/statusor.h
template <typename U = T, absl::enable_if_t<
absl::conjunction<
internal_statusor::IsDirectInitializationValid<T, U&&>,
absl::disjunction<
std::is_same<absl::remove_cvref_t<U>, T>,
absl::conjunction<
absl::negation<std::is_constructible<absl::Status, U&&>>,
absl::negation<
internal_statusor::HasConversionOperatorToStatusOr<
T, U&&>>>>,
std::is_constructible<T, U&&>,
absl::negation<std::is_convertible<U&&, T>>>::value,
int> = 0>
void StatusOr<T> (U && u)
Defined at line 477 of file ../../third_party/abseil-cpp/absl/status/statusor.h
bool ok ()
StatusOr
<T
>::ok()
Returns whether or not this `absl::StatusOr
<T
>` holds a `T` value. This
member function is analogous to `absl::Status::ok()` and should be used
similarly to check the status of return values.
Example:
StatusOr
<Foo
> result = DoBigCalculationThatCouldFail();
if (result.ok()) {
// Handle result
else {
// Handle error
}
Defined at line 494 of file ../../third_party/abseil-cpp/absl/status/statusor.h
template <typename... Args>
T & emplace (Args &&... args)
StatusOr
<T
>::emplace()
Reconstructs the inner value T in-place using the provided args, using the
T(args...) constructor. Returns reference to the reconstructed `T`.
Defined at line 590 of file ../../third_party/abseil-cpp/absl/status/statusor.h
template <typename U, typename... Args, absl::enable_if_t<
std::is_constructible<T, std::initializer_list<U>&, Args&&...>::value,
int> = 0>
T & emplace (std::initializer_list<U> ilist, Args &&... args)
Defined at line 606 of file ../../third_party/abseil-cpp/absl/status/statusor.h
void StatusOr<T> ()
Constructs a new `absl::StatusOr` with an `absl::StatusCode::kUnknown`
status. This constructor is marked 'explicit' to prevent usages in return
values such as 'return {};', under the misconception that
`absl::StatusOr
<std
::vector
<int
>>` will be initialized with an empty
vector, instead of an `absl::StatusCode::kUnknown` error code.
Defined at line 698 of file ../../third_party/abseil-cpp/absl/status/statusor.h
template <typename... Args>
void StatusOr<T> (absl::in_place_t , Args &&... args)
Constructs the inner value `T` in-place using the provided args, using the
`T(args...)` constructor.
Defined at line 720 of file ../../third_party/abseil-cpp/absl/status/statusor.h
template <typename U, typename... Args>
void StatusOr<T> (absl::in_place_t , std::initializer_list<U> ilist, Args &&... args)
Defined at line 725 of file ../../third_party/abseil-cpp/absl/status/statusor.h
const Status & status ()
StatusOr
<T
>::status()
Returns a reference to the current `absl::Status` contained within the
`absl::StatusOr
<T
>`. If `absl::StatusOr
<T
>` contains a `T`, then this
function returns `absl::OkStatus()`.
Defined at line 731 of file ../../third_party/abseil-cpp/absl/status/statusor.h
Status status ()
Defined at line 735 of file ../../third_party/abseil-cpp/absl/status/statusor.h
const T & value ()
StatusOr
<T
>::value()
Returns a reference to the held value if `this->ok()`. Otherwise, throws
`absl::BadStatusOrAccess` if exceptions are enabled, or is guaranteed to
terminate the process if exceptions are disabled.
If you have already checked the status using `this->ok()`, you probably
want to use `operator*()` or `operator->()` to access the value instead of
`value`.
Note: for value types that are cheap to copy, prefer simple code:
T value = statusor.value();
Otherwise, if the value type is expensive to copy, but can be left
in the StatusOr, simply assign to a reference:
T
&
value = statusor.value(); // or `const T
&
`
Otherwise, if the value type supports an efficient move, it can be
used as follows:
T value = std::move(statusor).value();
The `std::move` on statusor instead of on the whole expression enables
warnings about possible uses of the statusor object after the move.
Defined at line 740 of file ../../third_party/abseil-cpp/absl/status/statusor.h
T & value ()
Defined at line 746 of file ../../third_party/abseil-cpp/absl/status/statusor.h
const T && value ()
Defined at line 752 of file ../../third_party/abseil-cpp/absl/status/statusor.h
T && value ()
Defined at line 760 of file ../../third_party/abseil-cpp/absl/status/statusor.h
const T & operator* ()
StatusOr
<T
>:: operator*()
Returns a reference to the current value.
REQUIRES: `this->ok() == true`, otherwise the behavior is undefined.
Use `this->ok()` to verify that there is a current value within the
`absl::StatusOr
<T
>`. Alternatively, see the `value()` member function for a
similar API that guarantees crashing or throwing an exception if there is
no current value.
Defined at line 768 of file ../../third_party/abseil-cpp/absl/status/statusor.h
T & operator* ()
Defined at line 774 of file ../../third_party/abseil-cpp/absl/status/statusor.h
const T && operator* ()
Defined at line 780 of file ../../third_party/abseil-cpp/absl/status/statusor.h
T && operator* ()
Defined at line 786 of file ../../third_party/abseil-cpp/absl/status/statusor.h
const T * operator-> ()
StatusOr
<T
>::operator->()
Returns a pointer to the current value.
REQUIRES: `this->ok() == true`, otherwise the behavior is undefined.
Use `this->ok()` to verify that there is a current value.
Defined at line 792 of file ../../third_party/abseil-cpp/absl/status/statusor.h
T * operator-> ()
Defined at line 798 of file ../../third_party/abseil-cpp/absl/status/statusor.h
template <typename U>
T value_or (U && default_value)
StatusOr
<T
>::value_or()
Returns the current value if `this->ok() == true`. Otherwise constructs a
value using the provided `default_value`.
Unlike `value`, this function returns by value, copying the current value
if necessary. If the value type supports an efficient move, it can be used
as follows:
T value = std::move(statusor).value_or(def);
Unlike with `value`, calling `std::move()` on the result of `value_or` will
still trigger a copy.
Defined at line 804 of file ../../third_party/abseil-cpp/absl/status/statusor.h
template <typename U>
T value_or (U && default_value)
Defined at line 813 of file ../../third_party/abseil-cpp/absl/status/statusor.h
void IgnoreError ()
StatusOr
<T
>::IgnoreError()
Ignores any errors. This method does nothing except potentially suppress
complaints from any tools that are checking that errors are not dropped on
the floor.
Defined at line 822 of file ../../third_party/abseil-cpp/absl/status/statusor.h
Friends
template <typename U>
class StatusOr