void swap(packaged_task& other) noexcept;
概要
他のpackaged_task
オブジェクトと値を入れ替える
効果
*this
とother
が持つ共有状態とタスクを入れ替える。
戻り値
なし
例外
投げない
例
#include <iostream>
#include <future>
int foo() { return 1; }
int bar() { return 2; }
int main()
{
std::packaged_task<int()> task1(foo);
std::packaged_task<int()> task2(bar);
task1.swap(task2);
std::future<int> f1 = task1.get_future();
std::future<int> f2 = task2.get_future();
task1();
task2();
std::cout << f1.get() << std::endl;
std::cout << f2.get() << std::endl;
}
出力
2
1
バージョン
言語
- C++11
処理系
- Clang: ??
- GCC: 4.7.0 ✅
- ICC: ??
- Visual C++: 2012 ✅