public member function
<queue>

std::swap (priority_queue)

template <class T, class Container, class Compare>
  void swap (queue<T,Container,Compare>& x, queue <T,Container,Compare>& y) noexcept(noexcept(x.swap(y)));
Exchange contents of priority queues
Exchanges the contents of x and y.

Parameters

x,y
priority_queue 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 priority_queues
#include <iostream>       // std::cout
#include <queue>          // std::priority_queue, std::swap(priority_queue)

int main ()
{
  std::priority_queue<int> foo,bar;
  foo.push (15); foo.push(30); foo.push(10);
  bar.push (101); bar.push(202);

  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 containers, x and y, are modified.

Exception safety

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

See also