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

std::

swap (queue)

公共成员函数   <queue>

template <class T, class Container>
  void swap (queue&T,Container>& x, queue<T,Container>& y) noexcept(noexcept(x.swap(y)));

交换队列的内容

交换x和y的内容。

☲  参数


x,y
相同类型的队列 容器。大小可能不同。

☉  返回值



none

☣  示例



// swap queues
#include <iostream>       // std::cout
#include <queue>          // std::queue, std::swap(queue)

int main ()
{
  std::queue<int> foo,bar;
  foo.push (10); foo.push(20); foo.push(30);
  bar.push (111); bar.push(222);

  swap(foo,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

✥ 复杂度



常量

⇄ 数据竞争


y和x都被修改。

☂ 异常安全性



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

🍄  另请参阅



queues::swap 交换内容(公众成员函数)
swap 交换两个对象的值(函数模板)

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