friend void swap(node_handle& x, node_handle& y) noexcept(noexcept(x.swap(y)));
概要
2つの値を入れ替える。
要件
一方のノードハンドルが空である。または、allocator_traits<allocator_type>::propagate_on_container_swap
がtrue
である。または、両方のアロケータが等値である。
効果
x.swap(y);
戻り値
なし
例
#include <iostream>
#include <map>
int main()
{
std::map<int, char> m = {
{10, 'a'},
{20, 'b'},
{30, 'c'}
};
// ノードを取得
std::map<int, char>::node_type node1 = m.extract(10);
std::map<int, char>::node_type node2 = m.extract(20);
std::cout << "node1 : [" << node1.key() << ", " << node1.mapped() << "]" << std::endl;
std::cout << "node2 : [" << node2.key() << ", " << node2.mapped() << "]\n" << std::endl;
// ノードを入れ替える
std::swap(node1, node2);
std::cout << "node1 : [" << node1.key() << ", " << node1.mapped() << "]" << std::endl;
std::cout << "node2 : [" << node2.key() << ", " << node2.mapped() << "]" << std::endl;
}
出力
node1 : [10, a]
node2 : [20, b]
node1 : [20, b]
node2 : [10, a]
バージョン
言語
- C++17
処理系
- Clang: 7.0.0
- GCC: 7.1.0
- ICC: ??
- Visual C++: 2017 Update 5