std::basic_string<CharT,Traits,Allocator>::append_range
来自 cppreference.cn
< cpp | string | 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()));
目录 |
[编辑] 参数
rg | - | 一个容器兼容范围 |
[编辑] 返回值
*this
[编辑] 复杂度
与 rg 的大小呈线性关系。
[编辑] 异常
如果操作会导致 size()
超出 max_size()
,则抛出 std::length_error。
如果由于任何原因抛出异常,此函数无效果(强异常安全保证)。
[编辑] 注意
特性测试宏 | 值 | 标准 | 特性 |
---|---|---|---|
__cpp_lib_containers_ranges |
202202L |
(C++23) | 接受容器兼容范围的成员函数 |
[编辑] 示例
运行此代码
#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"); }
[编辑] 参阅
将字符追加到末尾 (public 成员函数) |