Exchange the value of the specified a object with that of the specified b object; also exchange the allocator of a with that of b if the (template parameter) type ALLOCATOR has the propagate_on_container_swap trait, and do not modify either allocator otherwise. This function provides the no-throw exception-safety guarantee. This operation has O[1] complexity if either a was created with the same allocator as b or ALLOCATOR has the propagate_on_container_swap trait; otherwise, it has O[n + m] complexity, where n and m are the lengths of a and b, respectively. Note that this function`s support for swapping objects created with different allocators when ALLOCATOR does not have the propagate_on_container_swap trait is a departure from the C++ Standard.
Declared in <bslstl_string.h>
template<
class CHAR_TYPE,
class CHAR_TRAITS,
class ALLOCATOR>
void
swap(
basic_string<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>& a,
basic_string<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>& b) noexcept(noexcept(a.swap(b)));