[#bsl-swap-0cc]
= xref:bsl.adoc[bsl]::swap
:relfileprefix: ../
:mrdocs:

Exchange the value and comparator of `a` with those of `b`&period;

== Synopsis

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

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    class KEY,
    class VALUE,
    class COMPARATOR,
    class ALLOCATOR&gt;
void
swap(
    xref:bsl/map-0a7.adoc[map&lt;KEY, VALUE, COMPARATOR, ALLOCATOR&gt;]& a,
    xref:bsl/map-0a7.adoc[map&lt;KEY, VALUE, COMPARATOR, ALLOCATOR&gt;]& b) noexcept(false);
----

== Description

Exchange the value and comparator of the specified `a` object with those of the specified `b` object&semi; also exchange the allocator of `a` with that of `b` if the (template parameter) type `ALLOCATOR` has the `propagate&lowbar;on&lowbar;container&lowbar;swap` trait, and do not modify either allocator otherwise&period; This function provides the no&hyphen;throw exception&hyphen;safety guarantee if and only if the (template parameter) type `COMPARATOR` provides a no&hyphen;throw swap operation, and provides the basic exception&hyphen;safety guarantee otherwise&semi; if an exception is thrown, both objects are left in valid but unspecified states&period; This operation has `O&lsqb;1&rsqb;` complexity if either `a` was created with the same allocator as `b` or `ALLOCATOR` has the `propagate&lowbar;on&lowbar;container&lowbar;swap` trait&semi; otherwise, it has `O&lsqb;n &plus; m&rsqb;` complexity, where `n` and `m` are the number of elements in `a` and `b`, respectively&period; Note that this function&apos;s support for swapping objects created with different allocators when `ALLOCATOR` does not have the `propagate&lowbar;on&lowbar;container&lowbar;swap` trait is a departure from the C&plus;&plus; Standard&period;

== Parameters

[cols="1,4"]
|===
| Name| Description
| *a*
| first map to swap
| *b*
| second map to swap
|===


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