std::deque<T,Allocator>::append_range
来自 cppreference.cn
template< container-compatible-range<T> R > void append_range( R&& rg ); |
(since C++23) | |
在 end()
之前,以非逆序方式插入来自范围 rg 的元素副本。
所有迭代器(包括 end()
迭代器)均失效。没有引用会失效。
rg 中的每个迭代器都会被精确解引用一次。
目录 |
[edit] 参数
rg | - | 一个容器兼容范围,即一个元素可转换为 T 的 input_range |
类型要求 | ||
-T 必须可从 *ranges::begin(rg) 就地构造 (EmplaceConstructible) 到 deque 中。否则,行为未定义。 |
[edit] 返回值
(无)
[edit] 复杂度
与 rg 的大小呈线性关系。调用 T
构造函数的次数正好等于 std::ranges::size(rg))。
[edit] 异常
如果抛出异常,但不是由 T
的复制构造函数、移动构造函数、赋值运算符或移动赋值运算符抛出的,则没有影响。如果在任一端插入单个元素时抛出异常,则没有影响。否则,如果非 CopyInsertable 类型 T
的移动构造函数抛出异常,则效果未指定。
注释
特性测试宏 | 值 | Std | 特性 |
---|---|---|---|
__cpp_lib_containers_ranges |
202202L |
(C++23) | 范围感知构造和插入 |
[edit] 示例
运行此代码
#include <cassert> #include <deque> #include <list> int main() { auto head = std::deque{1, 2, 3, 4}; const auto tail = std::list{-5, -6, -7}; #ifdef __cpp_lib_containers_ranges head.append_range(tail); #else head.insert(head.end(), tail.cbegin(), tail.cend()); #endif assert((head == std::deque{1, 2, 3, 4, -5, -6, -7})); }
[edit] 参见
(C++23) |
将一系列元素添加到开头 (公共成员函数) |
(C++23) |
插入一系列元素 (公共成员函数) |
将一个元素添加到末尾 (公共成员函数) | |
(C++11) |
在末尾就地构造一个元素 (公共成员函数) |