[#absl-StatusOr-value_or-03] = xref:absl.adoc[absl]::xref:absl/StatusOr.adoc[StatusOr]::value_or :relfileprefix: ../../ :mrdocs: Returns the held value, or a default when no value is present. == Synopsis Declared in `<absl/status/statusor.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- 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 [cols="1,4"] |=== | Name| Description | *default_value* | The value returned when no held value is present. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#