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

std::

function::swap (function)

公共成员函数  <functional>

template <class Ret, class... Args>
  void swap (function<Ret(Args...)>& x, function<Ret(Args...)>& y);

交换目标对象

将x的目标可调用对象与y的交换。

它的行为就像调用 x.swap(y)。

☲  参数


x,y
相同类型的function对象(具有相同的签名,由其模板形参如Ret和Args…定义)。

☉  返回值



none

☣  示例



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

⇄ 数据竞争



对象x和y都被修改。

☂ 异常安全性



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

🍄  另请参阅



swap 交换两个对象的值(函数模板)
function::swap 交换目标(公共成员函数)
function::assign 赋值目标并分配空间(公共成员函数)

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