std::basic_string<CharT,Traits,Allocator>::swap
: cppreference.com
<tbody>
</tbody>
<tbody class="t-dcl-rev ">
</tbody><tbody>
</tbody>
void swap( basic_string& other ); |
(C++17) | |
void swap( basic_string& other ) noexcept(/* see below */); |
(C++17) (C++20) |
|
constexpr void swap( basic_string& other ) noexcept(/* see below */); |
(C++20) | |
other
|
|
(C++11) |
| other | - |
()
|
noexcept :
noexcept(std::allocator_traits<Allocator>::propagate_on_container_swap::value || std::allocator_traits<Allocator>::is_always_equal::value) |
(C++17) |
Run this code
#include <string>
#include <iostream>
int main()
{
std::string a = "AAA";
std::string b = "BBB";
std::cout << "before swap" << '\n';
std::cout << "a: " << a << '\n';
std::cout << "b: " << b << '\n';
a.swap(b);
std::cout << "after swap" << '\n';
std::cout << "a: " << a << '\n';
std::cout << "b: " << b << '\n';
}
:
before swap
a: AAA
b: BBB
after swap
a: BBB
b: AAA