名前空間
変種
操作

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

From cppreference.com
< cpp‎ | string‎ | basic string
 
 
 
std::basic_string
 
template< class 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 - a コンテナ互換範囲

[編集] 戻り値

*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 member function) [編集]
English 日本語 中文(简体) 中文(繁體)