public member function
<functional>

std::function::swap

void swap (function& x) noexcept;
交換目標
x 中的可呼叫物件交換物件中儲存的可呼叫物件。

引數

x
一個同類型的 function 物件(具有相同的簽名,如其模板引數所描述)。

返回值



示例

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

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

  foo.swap(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.


資料競爭

*thisx 都會被修改。

異常安全

無異常保證:此成員函式從不丟擲異常。

另見