std::basic_string<CharT,Traits,Allocator>::assign_range
From cppreference.com
< cpp | string | basic string
| template< class container-compatible-range<CharT> R > constexpr std::basic_string& assign_range( R&& rg ); |
(C++23から) | |
範囲 rg の値で文字列の内容を置き換えます。
以下と等価です。
return assign( 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() { const auto source = {'s', 'o', 'u', 'r', 'c', 'e'}; std::string destination{"destination"}; #ifdef __cpp_lib_containers_ranges destination.assign_range(source); #else destination.assign(source.begin(), source.end()); #endif assert(destination == "source"); }
[編集] 関連項目
| 文字列に文字を代入する (public member function) | |
| 文字列に値を代入する (public member function) | |
basic_string を構築する(public member function) |