public member function
<queue>

std::priority_queue::swap

void swap (priority_queue& x) noexcept (/*see below*/);
交換內容
透過呼叫相應的(未加限定的)swap 非成員函式,交換容器介面卡的內容與x,同時交換底層容器值和它們的比較函式

此成員函式具有一個 noexcept 說明符,該說明符與底層容器比較函式swap 操作的組合 noexcept 匹配。

引數

x
另一個同類型的 priority_queue 容器介面卡(即,使用相同的模板引數 TContainerCompare 例項化)。大小可能不同。

返回值



示例

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


複雜度

常量。

資料競爭

both *this and x are modified.

異常安全

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

另見