A RetroSearch Logo

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

Search Query:

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

public member function

<stack>

std::swap (stack)
template <class T, class Container>  void swap (stack<T,Container>& x, stack<T,Container>& y) noexcept(noexcept(x.swap(y)));

Exchange contents of stacks

Exchanges the contents of x and y.

Parameters
x,y
stack containers of the same type. Size may differ.

Return value none

Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// swap stacks
#include <iostream>       // std::cout
#include <Stack>          // std::stack, std::swap(stack)

int main ()
{
  std::stack<int> foo,bar;
  foo.push (10); foo.push(20); foo.push(30);
  bar.push (111); bar.push(222);

  swap(foo,bar);

  std::cout << "size of foo: " << foo.size() << '\n';
  std::cout << "size of bar: " << bar.size() << '\n';

  return 0;
}

Output:
size of foo: 2
size of bar: 3


Complexity Constant.

Data races Both container adaptors, x and y, are modified.

Exception safety Provides the same level of guarantees as the operation performed on the underlying container objects.

See also
stack::swap
Swap contents (public member function)
swap
Exchange values of two objects (function template)

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