std::queue swap()
- 自 C++11 起
// Non const version only
void swap( priority_queue& other ) noexcept(/* see below*/);
将容器适配器的内容与 other
的内容进行交换。
注意
有效执行
using std::swap;
swap(c, other.c);
参数
other
- 用于交换内容的容器适配器
返回值
(无)
异常
- 自 C++17 起
- 自 C++11 起
noexcept 规范
noexcept(std::is_nothrow_swappable_v<Container> &&
std::is_nothrow_swappable_v<Compare>)
noexcept 规范
noexcept(noexcept(swap(c, other.c)) && noexcept(swap(comp, other.comp)))
在上述表达式中,标识符 swap 的查找方式与 C++17 std::is_nothrow_swappable
特性所使用的方式相同。
复杂度
等同于底层容器的 swap
。
注意
对于标准容器,复杂度保证为
- 容器大小的线性复杂度 - O(size()),适用于
std::array
。 - 常量 - O(1),适用于所有其他容器。
备注
一些实现(例如 libc++)提供 swap 成员函数作为 C++11 之前模式的扩展。
示例
重要
本节需要改进。您可以通过编辑此文档页面来帮助我们。