std::basic_string<CharT,Traits,Allocator>:: assign_range
From cppreference.net
<
cpp
|
string
|
basic string
C++
Strings library
| Classes | ||||
|
(C++17)
|
||||
std::basic_string
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
template
<
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 container compatible range |
戻り値
* this
計算量
rg のサイズに対して線形。
例外
操作によって
size()
が
max_size()
を超える場合、
std::length_error
をスローします。
何らかの理由で例外がスローされた場合、この関数は何も効果を持ちません( strong exception safety guarantee )。
注記
| 機能テスト マクロ | 値 | 標準 | 機能 |
|---|---|---|---|
__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"); }
関連項目
|
文字列に文字を割り当てる
(公開メンバ関数) |
|
|
文字列に値を代入する
(公開メンバ関数) |
|
basic_string
を構築する
(公開メンバ関数) |