public member function
<functional>

std::swap (function)

template <class Ret, class... Args>  void swap (function<Ret(Args...)>& x, function<Ret(Args...)>& y);
交換目標
x 中儲存的 target 可呼叫物件y 中儲存的進行交換。

其行為如同呼叫了 x.swap(y)

引數

x,y
function 物件,必須是同一型別(具有相同的簽名,由模板引數 RetArgs... 描述)。

返回值



示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// swapping functions
#include <iostream>     // std::cout
#include <functional>   // std::function, std::plus

int main () {
  std::function<int(int,int)> foo,bar;
  foo = std::plus<int>();

  swap(foo,bar);

  std::cout << "foo is " << (foo ? "callable" : "not callable") << ".\n";
  std::cout << "bar is " << (bar ? "callable" : "not callable") << ".\n";

  return 0;
}

輸出
foo is not callable.
bar is callable.


資料競爭

兩個物件,xy,都被修改。

異常安全

無異常保證: 絕不丟擲異常。

另見