A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/functional/function/swap-free/ below:

public member function

<functional>

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

Exchanges the targets

The target callable object held by x is exchanged with that of y.

It behaves as if x.swap(y) was called.



Parameters
x,y
function objects of the same type (with the same signature, as described by the template parameters Ret and Args...).

Return value none

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

Output:
foo is not callable.
bar is callable.


Data races Both objects, x and y, are modified.

Exception safetyNo-throw guarantee: never throws exceptions.

See also
function::swap
Swap targets (public member function)
swap
Exchange values of two objects (function template)
function::assign
Assign target and allocator (public member function)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4