Home C&C++函数库 c++ 语法 程序源码 Linux C库

std::

function::swap

公共成员函数  <functional>

void swap (function& x) noexcept;

交换目标对象
将存储在对象中的目标可调用对象交换为x中的。

☲  参数


x
相同类型的function对象(具有相同的签名,由其模板形参描述)。

☉  返回值



none

☣  示例



// 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.

⇄ 数据竞争



*this和x都被修改了。

☂ 异常安全性



无抛出保证:该成员函数从不抛出异常。

🍄  另请参阅



swap(function) 交换目标(公共成员函数)
function::operator= 赋值函数对象(公共成员函数)

联系我们 免责声明 关于CandCplus 网站地图