void swap (priority_queue& x) noexcept (/*see below*/);
noexcept specifier that matches the combined noexcept of the swap operations on the underlying container and the comparison functions.1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// priority_queue::swap
#include <iostream> // std::cout
#include <queue> // std::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);
foo.swap(bar);
std::cout << "size of foo: " << foo.size() << '\n';
std::cout << "size of bar: " << bar.size() << '\n';
return 0;
}
size of foo: 2 size of bar: 3