public member function
<functional>

std::function::swap

void swap (function& x) noexcept;
Swap targets
Exchanges the target callable object stored in the object by the one in x.

Parameters

x
A function object of the same type (with the same signature, as described by its template parameters).

Return value

none

Example

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;
}

Output:
foo is not callable.
bar is callable.


Data races

Both *this and x are modified.

Exception safety

No-throw guarantee: this member function never throws exceptions.

See also