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

Assignment operators

== Synopses

Declared in `&lt;beman&sol;optional&sol;optional&period;hpp&gt;`

Copy assigns the value from `rhs` if it has one&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
constexpr
xref:beman/optional/optional-03.adoc[optional]&
xref:beman/optional/optional-03/operator_assign-06.adoc[operator&equals;](xref:beman/optional/optional-03.adoc[optional] const& other)
requires std&colon;&colon;is&lowbar;copy&lowbar;constructible&lowbar;v&lt;T&gt; &amp;&amp; std&colon;&colon;is&lowbar;copy&lowbar;assignable&lowbar;v&lt;T&gt; &amp;&amp;
                     std&colon;&colon;is&lowbar;trivially&lowbar;copy&lowbar;constructible&lowbar;v&lt;T&gt; &amp;&amp; std&colon;&colon;is&lowbar;trivially&lowbar;copy&lowbar;assignable&lowbar;v&lt;T&gt; = default;
----

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

Copy assigns the value from `rhs` if it has one&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
constexpr
xref:beman/optional/optional-03.adoc[optional&lt;T&gt;]&
xref:beman/optional/optional-03/operator_assign-09.adoc[operator&equals;](xref:beman/optional/optional-03.adoc[optional] const& rhs)
requires std&colon;&colon;is&lowbar;copy&lowbar;constructible&lowbar;v&lt;T&gt; &amp;&amp; std&colon;&colon;is&lowbar;copy&lowbar;assignable&lowbar;v&lt;T&gt; &amp;&amp;
             (!std&colon;&colon;is&lowbar;trivially&lowbar;copy&lowbar;assignable&lowbar;v&lt;T&gt;);
----

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

Assigns the contained value from `rhs` if it has one, destroying the old value if there


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class U&gt;
constexpr
xref:beman/optional/optional-03.adoc[optional&lt;T&gt;]&
xref:beman/optional/optional-03/operator_assign-08.adoc[operator&equals;](xref:beman/optional/optional-03.adoc[optional&lt;U&gt;] const& rhs)
requires (detail&colon;&colon;enable&lowbar;assign&lowbar;from&lowbar;other&lt;T, U, const U&amp;&gt;);
----

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

Move assigns the value from `rhs` if it has one&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
constexpr
xref:beman/optional/optional-03.adoc[optional]&
xref:beman/optional/optional-03/operator_assign-0d.adoc[operator&equals;](xref:beman/optional/optional-03.adoc[optional]&& other)
requires std&colon;&colon;is&lowbar;move&lowbar;constructible&lowbar;v&lt;T&gt; &amp;&amp; std&colon;&colon;is&lowbar;move&lowbar;assignable&lowbar;v&lt;T&gt; &amp;&amp;
                     std&colon;&colon;is&lowbar;trivially&lowbar;move&lowbar;constructible&lowbar;v&lt;T&gt; &amp;&amp; std&colon;&colon;is&lowbar;trivially&lowbar;move&lowbar;assignable&lowbar;v&lt;T&gt; = default;
----

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

Move assigns the value from `rhs` if it has one&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
constexpr
xref:beman/optional/optional-03.adoc[optional&lt;T&gt;]&
xref:beman/optional/optional-03/operator_assign-0b8.adoc[operator&equals;](xref:beman/optional/optional-03.adoc[optional]&& rhs) noexcept(std&colon;&colon;is&lowbar;nothrow&lowbar;move&lowbar;constructible&lowbar;v&lt;T&gt;)
requires std&colon;&colon;is&lowbar;move&lowbar;constructible&lowbar;v&lt;T&gt; &amp;&amp; std&colon;&colon;is&lowbar;move&lowbar;assignable&lowbar;v&lt;T&gt; &amp;&amp;
             (!std&colon;&colon;is&lowbar;trivially&lowbar;move&lowbar;assignable&lowbar;v&lt;T&gt;);
----

[.small]#xref:beman/optional/optional-03/operator_assign-0b8.adoc[_» more&period;&period;&period;_]#

Assigns the contained value from `rhs` if it has one, destroying the old value if there


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class U&gt;
constexpr
xref:beman/optional/optional-03.adoc[optional&lt;T&gt;]&
xref:beman/optional/optional-03/operator_assign-07.adoc[operator&equals;](xref:beman/optional/optional-03.adoc[optional&lt;U&gt;]&& rhs)
requires (detail&colon;&colon;enable&lowbar;assign&lowbar;from&lowbar;other&lt;T, U, U&gt;);
----

[.small]#xref:beman/optional/optional-03/operator_assign-07.adoc[_» more&period;&period;&period;_]#

Resets the optional to an empty state&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
constexpr
xref:beman/optional/optional-03.adoc[optional&lt;T&gt;]&
xref:beman/optional/optional-03/operator_assign-0f.adoc[operator&equals;](xref:beman/optional/nullopt_t.adoc[nullopt&lowbar;t] value) noexcept;
----

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

Assigns the contained value from `u,` destroying the old value if there


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class U = T&gt;
constexpr
xref:beman/optional/optional-03.adoc[optional&lt;T&gt;]&
xref:beman/optional/optional-03/operator_assign-0b6.adoc[operator&equals;](U&& u)
requires detail&colon;&colon;enable&lowbar;assign&lowbar;forward&lt;T, U&gt;;
----

[.small]#xref:beman/optional/optional-03/operator_assign-0b6.adoc[_» more&period;&period;&period;_]#

== Return Value

optional&amp;

== Template Parameters

[cols="1,4"]
|===
|Name|Description

| *U*
| The type of the value to assign&period;
|===

== Parameters

[cols="1,4"]
|===
|Name|Description

| *u*
| The value to assign&period;
|===


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