命名空间
变体
操作

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

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

rg 的每个元素的副本插入到 priority_queue 中,如同通过

然后恢复堆属性,如同通过 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_ranges 202202L (C++23) 范围感知(Ranges-aware)构造和插入

[编辑] 示例

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

输出

[4, 3, 2, 1]

[编辑] 参见

插入元素并对底层容器排序
(public member function) [edit]