[#BloombergLP-bslstl-Optional_Base-05-swap]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bslstl.adoc[bslstl]::xref:BloombergLP/bslstl/Optional_Base-05.adoc[Optional&lowbar;Base]::swap
:relfileprefix: ../../../
:mrdocs:

Exchange the values of two optionals&period;

== Synopsis

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

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
void
swap(xref:BloombergLP/bslstl/Optional_Base-05.adoc[Optional&lowbar;Base]& other) noexcept(&sol;&ast; see-below &ast;&sol;);
----

== Description

Efficiently exchange the value of this object with the value of the specified `other` object&period; This method provides the no&hyphen;throw exception&hyphen;safety guarantee if the template parameter `t&lowbar;TYPE` provides that guarantee and the result of the `hasValue` method for the two objects being swapped is the same&period; The behavior is undefined unless this object was created with the same allocator as `other`&period;

== Exception specification

This function is potentially-throwing unless `bsl&colon;&colon;is&lowbar;nothrow&lowbar;move&lowbar;constructible&lt;t&lowbar;TYPE&gt;&colon;&colon;value &amp;&amp; bsl&colon;&colon;is&lowbar;nothrow&lowbar;swappable&lt;t&lowbar;TYPE&gt;&colon;&colon;value`.

== Parameters

[cols="1,4"]
|===
| Name| Description
| *other*
| optional with which to exchange values
|===


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