basic_string::swap
void swap(basic_string& str);The member function swaps the controlled sequences between *this and str. If get_allocator() == str.get_allocator(), it does so in constant time, it throws no exceptions, and it invalidates no references, pointers, or iterators that designate elements in the two controlled sequences. Otherwise, it performs a number of element assignments and constructor calls proportional to the number of elements in the two controlled sequences.