std::basic_string<CharT,Traits,Allocator>::replace
const basic_string& str );
const basic_string& str );
const basic_string& str,
const basic_string& str,
(constexpr since C++20)
const CharT* cstr, size_type count2 );
const CharT* cstr, size_type count2 );
const CharT* cstr );
const CharT* cstr );
size_type count2, CharT ch );
size_type count2, CharT ch );
basic_string& replace( const_iterator first, const_iterator last,
std::initializer_list <CharT> ilist );
(constexpr since C++20)
basic_string& replace( size_type pos, size_type count,
(constexpr since C++20)
basic_string& replace( const_iterator first, const_iterator last,
(constexpr since C++20)
basic_string& replace( size_type pos, size_type count,
const StringViewLike& t,
(constexpr since C++20)
Replaces the characters in the range [begin() + pos, begin() + std::min (pos + count, size())) or [first, last) with given characters.
[pos2, std::min (pos2 + count2, str.size())) of str.[cstr, cstr + count2).[cstr, cstr + count2) is not a valid range, the behavior is undefined.[cstr, cstr + Traits::length(cstr)).[first2, last2) as if by replace(first, last, basic_string(first2, last2, get_allocator())).std::basic_string_view <CharT, Traits>> is true and std::is_convertible_v <const StringViewLike&, const CharT*> is false.
std::basic_string_view <CharT, Traits>> is true and std::is_convertible_v <const StringViewLike&, const CharT*> is false.
If [begin(), first) or [first, last) is not a valid range, the behavior is undefined.
[edit] Parameters
InputIt must meet the requirements of LegacyInputIterator.
[edit] Return value
*this.
[edit] Exceptions
If the operation would cause size() to exceed max_size() , throws std::length_error .
If an exception is thrown for any reason, these functions have no effect (strong exception safety guarantee).
[edit] Example
Reason: no example
[edit] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 847 | C++98 | there was no exception safety guarantee | added strong exception safety guarantee |
| LWG 1323 | C++98 | the types of first and last were iterator
|
changed to const_iterator
|
| LWG 2946 | C++17 | overloads (12,13) caused ambiguity in some cases | avoided by making them templates |
[edit] See also
(public member function) [edit]
(function template) [edit]