public member function
<queue>
std::swap (priority_queue)
template <class T, class Container, class Compare>
void swap (priority_queue<T,Container,Compare>& x,
priority_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.
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
|
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
- priority_queue::swap
- Swap contents (public member function
)
- swap
- Exchange values of two objects (function template
)