Returns the held value, or a default when no value is present.
Synopsis
Declared in <absl/status/statusor.h>
template<typename U>
requires internal_statusor::IsValueOrValid<T, U&&, false>::value
T
value_or(U&& default_value) const &;
Description
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.
Return Value
The held value if present, otherwise default_value.
Parameters
Name |
Description |
default_value |
The value returned when no held value is present. |
Created with MrDocs