Home C&C++函数库 c++ 语法 程序源码 Linux C库

std::

priority_queue::swap

公共成员函数   <queue>

void swap (priority_queue& x) noexcept(/*see below*/);

交换内容

用x的值交换容器适配器的内容,同时使用相应的swap非成员函数交换底层容器值和它们的比较函数。

该成员函数有一个noexcept说明符,该说明符匹配基础容器和比较函数上交换操作的组合noexcept。

☲  参数


x
另一个相同类型的priority_queue容器适配器(例如,用相同的模板参数实例化,T和container)。大小可能不同。

☉  返回值



none

☣  示例



// 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

✥ 复杂度



常量

⇄ 数据竞争


*this和x都被修改。

☂ 异常安全性



提供与在基础容器对象上执行的操作相同级别的保证。

🍄  另请参阅



swap (priority_queue) 交换优先队列的内容(公众成员函数)
swap 交换两个对象的值(函数模板)

联系我们 免责声明 关于CandCplus 网站地图