[#bsl-optional-072-operator_assign-01]
= xref:bsl.adoc[bsl]::xref:bsl/optional-072.adoc[optional]::operator&equals;
:relfileprefix: ../../
:mrdocs:

Assignment operators

== Synopses

Declared in `&lt;bslstl&lowbar;optional&period;h&gt;`

Assign to this object the value of the specified `rhs` object, and return a non&hyphen;`const` reference to this object&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:BloombergLP/bslstl/Optional_Base-05.adoc[Optional&lowbar;Base&lt;t&lowbar;TYPE, t&lowbar;USES&lowbar;BSLMA&lowbar;ALLOC&gt;]&
xref:BloombergLP/bslstl/Optional_Base-05/operator_assign-05.adoc[operator&equals;](xref:BloombergLP/bslstl/Optional_Base-05.adoc[Optional&lowbar;Base] const& rhs);
----

[.small]#xref:BloombergLP/bslstl/Optional_Base-05/operator_assign-05.adoc[_» more&period;&period;&period;_]#

Disengage this object if the specified `rhs` object is disengaged, and assign to this object the value of `rhs&period;value()` (of `t&lowbar;ANY&lowbar;TYPE`) converted to `t&lowbar;TYPE` otherwise&period; Return a reference providing modifiable access to this object&period; Note that this method does not participate in overload resolution unless `t&lowbar;TYPE` and `t&lowbar;ANY&lowbar;TYPE` are compatible&period; This assignment operator can be called in constant expressions only when neither `t&lowbar;TYPE` nor `t&lowbar;ANY&lowbar;TYPE` is allocator&hyphen;aware&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class t&lowbar;ANY&lowbar;TYPE&gt;
constexpr
xref:bsl/optional-072.adoc[optional&lt;t&lowbar;TYPE&gt;]&
xref:bsl/optional-072/operator_assign-08.adoc[operator&equals;](xref:bsl/optional-072.adoc[optional&lt;t&lowbar;ANY&lowbar;TYPE&gt;] const& rhs);
----

[.small]#xref:bsl/optional-072/operator_assign-08.adoc[_» more&period;&period;&period;_]#

Reset this object to be disengaged and return a reference providing modifiable access to this object&period; This assignment operator can be called in constant expressions only when `t&lowbar;TYPE` is not allocator&hyphen;aware&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
constexpr
xref:bsl/optional-072.adoc[optional&lt;t&lowbar;TYPE&gt;]&
xref:bsl/optional-072/operator_assign-09.adoc[operator&equals;](xref:bsl/nullopt_t.adoc[bsl::nullopt&lowbar;t]) noexcept;
----

[.small]#xref:bsl/optional-072/operator_assign-09.adoc[_» more&period;&period;&period;_]#

Assign to this object the value of the specified `rhs` object, and return a non&hyphen;`const` reference to this object&period; The allocators of this object and `rhs` both remain unchanged&period; The contents of `rhs` are either move&hyphen;constructed into or move&hyphen;assigned to this object&period; `rhs` is left in a valid but unspecified state&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:BloombergLP/bslstl/Optional_Base-05.adoc[Optional&lowbar;Base&lt;t&lowbar;TYPE, t&lowbar;USES&lowbar;BSLMA&lowbar;ALLOC&gt;]&
xref:BloombergLP/bslstl/Optional_Base-05/operator_assign-08.adoc[operator&equals;](xref:BloombergLP/bslmf/MovableRef.adoc[BloombergLP::bslmf::MovableRef&lt;Optional&lowbar;Base&gt;] rhs);
----

[.small]#xref:BloombergLP/bslstl/Optional_Base-05/operator_assign-08.adoc[_» more&period;&period;&period;_]#

Disengage this object if the specified `rhs` object is disengaged, and move assign to this object the value of `rhs&period;value()` (of `t&lowbar;ANY&lowbar;TYPE`) converted to `t&lowbar;TYPE` otherwise&period; Return a reference providing modifiable access to this object&period; Note that this method does not participate in overload resolution unless `t&lowbar;TYPE` and `t&lowbar;ANY&lowbar;TYPE` are compatible&period; This assignment operator can be called in constant expressions only when neither `t&lowbar;TYPE` nor `t&lowbar;ANY&lowbar;TYPE` is allocator&hyphen;aware&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class t&lowbar;ANY&lowbar;TYPE&gt;
constexpr
xref:bsl/optional-072.adoc[optional&lt;t&lowbar;TYPE&gt;]&
xref:bsl/optional-072/operator_assign-0f.adoc[operator&equals;](xref:BloombergLP/bslmf/MovableRef_Deduced.adoc[BloombergLP::bslmf::MovableRef&lowbar;Deduced&lt;optional&lt;t&lowbar;ANY&lowbar;TYPE&gt;&gt;] rhs);
----

[.small]#xref:bsl/optional-072/operator_assign-0f.adoc[_» more&period;&period;&period;_]#

Disengage this object if the specified `rhs` object is disengaged, and assign to this object the value of `rhs&period;value()` (of `t&lowbar;ANY&lowbar;TYPE`) converted to `t&lowbar;TYPE` otherwise&period; Return a reference providing modifiable access to this object&period; Note that this method does not participate in overload resolution unless `t&lowbar;TYPE` and `t&lowbar;ANY&lowbar;TYPE` are compatible&period; This assignment operator can be called in constant expressions only when `t&lowbar;TYPE` is not allocator&hyphen;aware&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class t&lowbar;ANY&lowbar;TYPE = t&lowbar;TYPE&gt;
constexpr
xref:bsl/optional-072.adoc[optional&lt;t&lowbar;TYPE&gt;]&
xref:bsl/optional-072/operator_assign-06.adoc[operator&equals;](std::optional&lt;t&lowbar;ANY&lowbar;TYPE&gt; const& rhs);
----

[.small]#xref:bsl/optional-072/operator_assign-06.adoc[_» more&period;&period;&period;_]#

Assign to this object the value of the specified `rhs` object converted to `t&lowbar;TYPE`, and return a reference providing modifiable access to this object&period; Note that this method may invoke assignment from `rhs`, or construction from `rhs`, depending on whether this object is engaged&period; This assignment operator does not participate in overload resolution if `t&lowbar;ANY&lowbar;TYPE` is possibly cv&hyphen;qualified `bsl&colon;&colon;optional&lt;t&lowbar;TYPE&gt;`&period; Also note that an assignment of the form `o &equals; &lcub;&rcub;&semi;`, where `o` is of type `optional`, will always assign to `o` the empty state, and never call this overload (see implementation notes)&period; This assignment operator can be called in constant expressions only when `t&lowbar;TYPE` is not allocator&hyphen;aware&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class t&lowbar;ANY&lowbar;TYPE = t&lowbar;TYPE&gt;
constexpr
xref:bsl/optional-072.adoc[optional&lt;t&lowbar;TYPE&gt;]&
xref:bsl/optional-072/operator_assign-0d.adoc[operator&equals;](t&lowbar;ANY&lowbar;TYPE&& rhs);
----

[.small]#xref:bsl/optional-072/operator_assign-0d.adoc[_» more&period;&period;&period;_]#

Disengage this object if the specified `rhs` object is disengaged, and move assign to this object the value of `rhs&period;value()` (of `t&lowbar;ANY&lowbar;TYPE`) converted to `t&lowbar;TYPE` otherwise&period; Return a reference providing modifiable access to this object&period; Note that this method does not participate in overload resolution unless `t&lowbar;TYPE` and `t&lowbar;ANY&lowbar;TYPE` are compatible&period; This assignment operator can be called in constant expressions only when `t&lowbar;TYPE` is not allocator&hyphen;aware&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class t&lowbar;ANY&lowbar;TYPE = t&lowbar;TYPE&gt;
constexpr
xref:bsl/optional-072.adoc[optional&lt;t&lowbar;TYPE&gt;]&
xref:bsl/optional-072/operator_assign-0e.adoc[operator&equals;](std::optional&lt;t&lowbar;ANY&lowbar;TYPE&gt;&& rhs);
----

[.small]#xref:bsl/optional-072/operator_assign-0e.adoc[_» more&period;&period;&period;_]#


[.small]#Created with https://www.mrdocs.com[MrDocs]#
