std::inplace_vector<T,N>::append_range
来自 cppreference.cn
< cpp | container | inplace vector
template< container-compatible-range<T> R > constexpr void append_range( R&& rg ); |
(since C++26) | |
从范围 rg 插入元素的副本到 end()
前,保持非逆序。
rg 中的每个迭代器都只被解引用一次。
目录 |
[编辑] 参数
rg | - | 一个 容器兼容范围,即一个 input_range ,其元素可转换为 T |
类型要求 | ||
-T 必须是 EmplaceConstructible,以便从 *ranges::begin(rg) 就地构造到 inplace_vector 中。否则,行为未定义。 |
[编辑] 返回值
(无)
[编辑] 复杂度
与 rg 的大小呈线性关系。调用 T
的构造函数的次数正好等于 std::ranges::size(rg))。
[编辑] 异常
如果 std::ranges::size(rg) > N,则抛出 std::bad_alloc。 如果抛出的异常不是由 T
的复制构造函数、移动构造函数、赋值运算符或移动赋值运算符或任何 InputIterator
操作引起的,则不会产生任何影响。 否则,如果抛出异常,则 size() >= n 并且范围 [
0,
n)
中的元素不会被修改,其中 n
是此调用前 size()
的值。
[编辑] 示例
运行此代码
#include <cassert> #include <inplace_vector> #include <iostream> int main() { using I = std::inplace_vector<int, 8>; auto head = I{1, 2, 3, 4}; const auto tail = {-5, -6, -7}; head.append_range(tail); assert(head.size() == 7 and (head == I{1, 2, 3, 4, -5, -6, -7})); try { head.append_range(tail); // throws: no space } catch(const std::bad_alloc&) { std::cout << "std::bad_alloc\n"; } }
输出
std::bad_alloc
[编辑] 参见
尝试在末尾添加一系列元素 (公共成员函数) | |
插入一系列元素 (公共成员函数) | |
在末尾添加一个元素 (公共成员函数) | |
在末尾就地构造一个元素 (公共成员函数) |