std::basic_string<CharT,Traits,Allocator>::swap (3) - Linux Manuals
std::basic_string<CharT,Traits,Allocator>::swap: std::basic_string<CharT,Traits,Allocator>::swap
NAME
std::basic_string<CharT,Traits,Allocator>::swap - std::basic_string<CharT,Traits,Allocator>::swap
Synopsis
void swap( basic_string& other ); (until C++17)
void swap( basic_string& other ) noexcept(/* see below */); (since C++17)
Exchanges the contents of the string with those of other. All iterators and references may be invalidated.
The behavior is undefined if Allocator does not propagate on swap and the allocators of *this and other are unequal. (since C++11)
Parameters
other - string to exchange the contents with
Return value
(none)
Exceptions
noexcept specification:
noexcept(std::allocator_traits<Allocator>::propagate_on_container_swap::value
|| std::allocator_traits<Allocator>::is_always_equal::value)
Example
// Run this code
Output:
Complexity
Constant.