std::basic_string<CharT,Traits,Allocator>:: replace
|
basic_string
&
replace
(
size_type pos, size_type count,
const basic_string & str ) ; |
(1) | (C++20以降 constexpr) |
|
basic_string
&
replace
(
const_iterator first, const_iterator last,
const basic_string & str ) ; |
(2) | (C++20以降 constexpr) |
| (3) | ||
|
basic_string
&
replace
(
size_type pos, size_type count,
const
basic_string
&
str,
|
(C++14まで) | |
|
basic_string
&
replace
(
size_type pos, size_type count,
const
basic_string
&
str,
|
(C++14から)
(C++20からconstexpr) |
|
|
basic_string
&
replace
(
size_type pos, size_type count,
const CharT * cstr, size_type count2 ) ; |
(4) | (constexpr C++20以降) |
|
basic_string
&
replace
(
const_iterator first, const_iterator last,
const CharT * cstr, size_type count2 ) ; |
(5) | (constexpr C++20以降) |
|
basic_string
&
replace
(
size_type pos, size_type count,
const CharT * cstr ) ; |
(6) | (constexpr C++20以降) |
|
basic_string
&
replace
(
const_iterator first, const_iterator last,
const CharT * cstr ) ; |
(7) | (constexpr C++20以降) |
|
basic_string
&
replace
(
size_type pos, size_type count,
size_type count2, CharT ch ) ; |
(8) | (constexpr C++20以降) |
|
basic_string
&
replace
(
const_iterator first, const_iterator last,
size_type count2, CharT ch ) ; |
(9) | (constexpr C++20以降) |
|
template
<
class
InputIt
>
basic_string
&
replace
(
const_iterator first, const_iterator last,
|
(10) | (constexpr C++20以降) |
|
basic_string
&
replace
(
const_iterator first, const_iterator last,
std:: initializer_list < CharT > ilist ) ; |
(11) |
(C++11以降)
(constexpr C++20以降) |
|
template
<
class
StringViewLike
>
basic_string
&
replace
(
size_type pos, size_type count,
|
(12) |
(C++17以降)
(constexpr C++20以降) |
|
template
<
class
StringViewLike
>
basic_string
&
replace
(
const_iterator first, const_iterator last,
|
(13) |
(C++17以降)
(constexpr C++20以降) |
|
template
<
class
StringViewLike
>
basic_string
&
replace
(
size_type pos, size_type count,
|
(14) |
(C++17以降)
(constexpr C++20以降) |
範囲
[
begin
(
)
+
pos
,
begin
(
)
+
std::
min
(
pos
+
count, size
(
)
)
)
または
[
first
,
last
)
の文字を指定された文字で置き換えます。
[
pos2
,
std::
min
(
pos2
+
count2, str.
size
(
)
)
)
で置き換えられます。
[
cstr
,
cstr
+
count2
)
内の文字で置き換えられます。
[
cstr
,
cstr
+
Traits
::
length
(
cstr
)
)
内の文字で置き換えられます。
[
first2
,
last2
)
内の文字で置き換えられます。これは、
replace
(
first, last, basic_string
(
first2, last2, get_allocator
(
)
)
)
によって行われるかのようです。
std:: basic_string_view < CharT, Traits >> が true であり、かつ std:: is_convertible_v < const StringViewLike & , const CharT * > が false である場合。
std:: basic_string_view < CharT, Traits >> が true であり、かつ std:: is_convertible_v < const StringViewLike & , const CharT * > が false である場合です。
[
begin
,
first
)
または
[
first
,
last
)
が
有効な範囲
でない場合、動作は未定義です。
目次 |
パラメータ
| pos | - | 置換対象の部分文字列の開始位置 |
| count | - | 置換対象の部分文字列の長さ |
| first, last | - | 置換対象の文字範囲 |
| str | - | 置換に使用する文字列 |
| pos2 | - | 置換元の部分文字列の開始位置 |
| count2 | - | 置換に使用する文字数 |
| cstr | - | 置換に使用する文字列へのポインタ |
| ch | - | 置換に使用する文字値 |
| first2, last2 | - | 置換に使用する文字範囲 |
| ilist | - | 置換に使用する文字の初期化子リスト |
| t | - | 置換に使用する文字列を持つオブジェクト( std::basic_string_view に変換可能) |
| 型要件 | ||
-
InputIt
は
LegacyInputIterator
の要件を満たさなければならない。
|
||
戻り値
* this .
例外
操作によって
size()
が
max_size()
を超える場合、
std::length_error
をスローします。
何らかの理由で例外がスローされた場合、これらの関数は何も効果を持ちません( strong exception safety guarantee )。
例
|
このセクションは不完全です
理由: 例がありません |
不具合報告
以下の動作変更の欠陥報告書は、以前に公開されたC++規格に対して遡及的に適用されました。
| DR | 適用対象 | 公開時の動作 | 正しい動作 |
|---|---|---|---|
| LWG 847 | C++98 | 例外安全性保証がなかった | 強い例外安全性保証を追加 |
| LWG 1323 | C++98 |
first
と
last
の型が
iterator
だった
|
const_iterator
に変更
|
| LWG 2946 | C++17 | オーバーロード (12,13) が一部の場合に曖昧性を引き起こした | テンプレート化することで回避 |
関連項目
|
(C++23)
|
文字列の指定された部分を文字の範囲で置き換える
(公開メンバ関数) |
|
(C++11)
|
正規表現の出現をフォーマットされた置換テキストで置き換える
(関数テンプレート) |
|
特定の条件を満たすすべての値を別の値で置き換える
(関数テンプレート) |