命名空间
变体
操作

std::basic_string<CharT,Traits,Allocator>::append_range

来自 cppreference.cn
< cpp‎ | string‎ | basic string
 
 
 
std::basic_string
 
template< container-compatible-range<CharT> R >
constexpr std::basic_string& append_range( R&& rg );
(自 C++23 起)

从范围 rg 追加所有字符。

等价于

return append(std::basic_string( std::from_range, std​::​forward<R>(rg), get_allocator()));

目录

[edit] 参数

rg - 容器兼容范围

[edit] 返回值

*this

[edit] 复杂度

rg 的大小呈线性关系。

[edit] 异常

如果操作将导致 size() 超过 max_size(),则抛出 std::length_error

如果由于任何原因抛出异常,则此函数不起作用(强异常安全保证)。

[edit] 注解

特性测试 Std 特性
__cpp_lib_containers_ranges 202202L (C++23) 接受容器兼容范围的成员函数

[edit] 示例

#include <cassert>
#include <string>
 
int main()
{
    std::string head{"long long"};
    const auto tail = {' ', 'i', 'n', 't'};
 
#ifdef __cpp_lib_containers_ranges
    head.append_range(tail);
#else
    head.append(tail.begin(), tail.end());
#endif
 
    assert(head == "long long int");
}

[edit] 参见

将字符追加到末尾
(公有成员函数) [编辑]