[#absl-StatusOr-operator_assign-01] = xref:absl.adoc[absl]::xref:absl/StatusOr.adoc[StatusOr]::operator= :relfileprefix: ../../ :mrdocs: Perfect‐forwarding value assignment operator. == Synopsis Declared in `<absl/status/statusor.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<typename U = T> requires internal_statusor::IsAssignmentValid<T, U, false>::value xref:absl/StatusOr.adoc[StatusOr]& operator=(U&& v); ---- == Description 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)`? == Return Value A reference to `*this`. == Parameters [cols="1,4"] |=== | Name| Description | *v* | The value to assign into the held object. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#