最終更新日時(UTC):
が更新

履歴 編集

function
<future>

std::packaged_task::swap(C++11)

void swap(packaged_task& other) noexcept;

概要

他のpackaged_taskオブジェクトと値を入れ替える

効果

*thisotherが持つ共有状態とタスクを入れ替える。

戻り値

なし

例外

投げない

#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

処理系

参照