[#bsl-swap-00c]
= xref:bsl.adoc[bsl]::swap
:relfileprefix: ../
:mrdocs:

Efficiently exchange the values of the specified `lhs` and `rhs` objects&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 `lhs` and `rhs` is the same&period; This function can be called in constant expressions only if `t&lowbar;TYPE` is not allocator&hyphen;aware&period;

== Synopsis

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

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class t&lowbar;TYPE&gt;
void
swap(
    xref:bsl/optional-072.adoc[bsl::optional&lt;t&lowbar;TYPE&gt;]& lhs,
    std::optional&lt;t&lowbar;TYPE&gt;& rhs)
requires !BloombergLP&colon;&colon;bslma&colon;&colon;UsesBslmaAllocator&lt;t&lowbar;TYPE&gt;&colon;&colon;value;
----


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