std::priority_queue<T,Container,Compare>::push_range

来自cppreference.com
template<container-compatible-range<value_type> R >
void push_range( R&& rg );
(C++23 起)

如同以如下方式,在 priority_queue 中插入 rg 的各元素:

然后如同调用 ranges::make_heap(c, comp) 来恢复堆属性。插入后 ranges::is_heap(c, comp)true

范围 rg 中的每个迭代器均恰好被解引用一次。

目录

[编辑]参数

rg - 容器兼容范围,即其元素可以转换为 Tinput_range

[编辑]复杂度

c.append_range 的复杂度,加上 ranges::make_heap(c, comp) 的复杂度。

[编辑]注解

功能特性测试标准功能特性
__cpp_lib_containers_ranges202202L(C++23)按范围构造和插入

[编辑]示例

#include <initializer_list>#include <stack>#include <version>#ifdef __cpp_lib_format_ranges#include <print>usingstd::println;#else#define FMT_HEADER_ONLY#include <fmt/ranges.h>using fmt::println;#endif   int main(){std::stack<int> adaptor;constauto rg ={1, 3, 2, 4};   #ifdef __cpp_lib_containers_ranges adaptor.push_range(rg);#elsefor(int e : rg) adaptor.push(e);#endif   println("{}", adaptor);}

输出:

[4, 3, 2, 1]

[编辑]参阅

插入元素,并对底层容器排序
(公开成员函数)[编辑]
close