命名空间
变体
操作

std::queue<T,Container>::push_range

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

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


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

内容

[edit] 参数

rg - 一个容器兼容范围,即一个input_range,其元素可转换为 T

[edit] 复杂度

c.append_rangeranges::copy(rg, std::back_inserter(c)) 的复杂度相同(取决于内部使用的函数)。

[edit] 注解

特性测试 Std 特性
__cpp_lib_containers_ranges 202202L (C++23) 范围感知 构造和插入

[edit] 示例

#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::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);
}

输出

[1, 3, 2, 4]

[edit] 参见

在末尾插入元素
(公共成员函数) [编辑]