Skip to content

Latest commit

 

History

History
79 lines (56 loc) · 1.28 KB

swap_free.md

File metadata and controls

79 lines (56 loc) · 1.28 KB

swap (非メンバ関数)

  • future[meta header]
  • std[meta namespace]
  • function template[meta id-type]
  • cpp11[meta cpp]
namespace std {
  template <class R, class... ArgTypes>
  void swap(packaged_task<R(ArgTypes...)>& x, packaged_task<R(ArgTypes...)>& y) noexcept;
}

概要

2つのpackaged_taskオブジェクトを入れ替える

効果

x.swap(y)

戻り値

なし

例外

投げない

#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);

  std::swap(task1, 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;
}
  • std::swap[color ff0000]
  • get_future()[link get_future.md]
  • std::future[link /reference/future/future.md]
  • get()[link /reference/future/future/get.md]

出力

2
1

バージョン

言語

  • C++11

処理系

参照