void swap(forward_list& x); // (1) C++17
void swap(forward_list& x)
noexcept(
allocator_traits<Allocator>::is_always_equal::value
); // (1) C++17
概要
他のforward_list
オブジェクトと値を入れ替える。
効果
*this
の内容をx
と交換する。
戻り値
なし
計算量
定数時間
例
#include <iostream>
#include <forward_list>
#include <algorithm>
int main()
{
std::forward_list<int> ls1 = {1, 2, 3};
std::forward_list<int> ls2 = {4, 5, 6};
ls1.swap(ls2);
std::for_each(ls1.begin(), ls1.end(), [](int x) {
std::cout << x << std::endl;
});
std::cout << std::endl;
std::for_each(ls2.begin(), ls2.end(), [](int x) {
std::cout << x << std::endl;
});
}
出力
4
5
6
1
2
3
バージョン
言語
- C++11
処理系
- Clang: ??
- GCC: 4.7.0
- ICC: ??
- Visual C++: 2010, 2012, 2013, 2015, 2017
参照
- N4258 Cleaning-up noexcept in the Library, Rev 3
noexcept
追加の経緯となる提案文書