std::
queue::swap
公共成员函数 <queue>
void swap (queue& x) noexcept(/*see below*/);
交换内容
用x的内容交换容器适配器(*this)的内容。
该成员函数调用非成员函数swap(非限定)来交换底层容器。
noexcept说明符匹配底层容器上的交换操作。
☲ 参数
-
x
-
另一个相同类型的队列容器适配器(例如,用相同的模板参数实例化,T和container)。大小可能不同。
☉ 返回值
none
☣ 示例
// queue::swap
#include <iostream> // std::cout
#include <queue> // std::queue
int main ()
{
std::queue<int> foo,bar;
foo.push (10); foo.push(20); foo.push(30);
bar.push (111); bar.push(222);
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 (queue) |
交换队列的内容(公众成员函数) |
swap |
交换两个对象的值(函数模板) |