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

履歴 編集

function
<functional>

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

void swap(function& other) noexcept;

概要

他のfunctionオブジェクトと中身を入れ替える。

効果

*thisが持つ関数とotherが持つ関数を交換する。

戻り値

なし

例外

投げない

#include <iostream>
#include <functional>

int ident(int x) { return x; }
int add(int x) { return x + 1; }

int main()
{
  std::function<int(int)> f = ident;
  std::function<int(int)> g = add;

  // fとgを交換
  f.swap(g);

  std::cout << f(1) << std::endl; // add
  std::cout << g(1) << std::endl; // ident
}

出力

2
1

バージョン

言語

  • C++11

処理系

参照