24 Strings library [strings]

24.3 String classes [string.classes]

24.3.2 Class template basic_­string [basic.string]

24.3.2.6 basic_­string modifiers [string.modifiers]

24.3.2.6.6 basic_­string​::​replace [string.replace]

basic_string& replace(size_type pos1, size_type n1, const basic_string& str);
Effects: Equivalent to: return replace(pos1, n1, str.data(), str.size());
basic_string& replace(size_type pos1, size_type n1, const basic_string& str, size_type pos2, size_type n2 = npos);
Throws: out_­of_­range if pos1 > size() or pos2 > str.size().
Effects: Determines the effective length rlen of the string to be inserted as the smaller of n2 and str.size() - pos2 and calls replace(pos1, n1, str.data() + pos2, rlen).
Returns: *this.
basic_string& replace(size_type pos1, size_type n1, basic_string_view<charT, traits> sv);
Effects: Equivalent to: return replace(pos1, n1, sv.data(), sv.size());
template<class T> basic_string& replace(size_type pos1, size_type n1, const T& t, size_type pos2, size_type n2 = npos);
Throws: out_­of_­range if pos1 > size() or pos2 > sv.size().
Effects: Creates a variable, sv, as if by basic_­string_­view<charT, traits> sv = t.
Determines the effective length rlen of the string to be inserted as the smaller of n2 and sv.size() - pos2 and calls replace(pos1, n1, sv.data() + pos2, rlen).
Remarks: This function shall not participate in overload resolution unless is_­convertible_­v<const T&, basic_­string_­view<charT, traits>> is true and is_­convertible_­v<const T&, const charT*> is false.
Returns: *this.
basic_string& replace(size_type pos1, size_type n1, const charT* s, size_type n2);
Requires: s points to an array of at least n2 elements of charT.
Throws: out_­of_­range if pos1 > size() or length_­error if the length of the resulting string would exceed max_­size() (see below).
Effects: Determines the effective length xlen of the string to be removed as the smaller of n1 and size() - pos1.
If size() - xlen >= max_­size() - n2 throws length_­error.
Otherwise, the function replaces the string controlled by *this with a string of length size() - xlen + n2 whose first pos1 elements are a copy of the initial elements of the original string controlled by *this, whose next n2 elements are a copy of the initial n2 elements of s, and whose remaining elements are a copy of the elements of the original string controlled by *this beginning at position pos + xlen.
Returns: *this.
basic_string& replace(size_type pos, size_type n, const charT* s);
Requires: s points to an array of at least traits​::​length(s) + 1 elements of charT.
Effects: Equivalent to: return replace(pos, n, s, traits​::​length(s));
basic_string& replace(size_type pos1, size_type n1, size_type n2, charT c);
Effects: Equivalent to replace(pos1, n1, basic_­string(n2, c)).
Returns: *this.
basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
Requires: [begin(), i1) and [i1, i2) are valid ranges.
Effects: Calls replace(i1 - begin(), i2 - i1, str).
Returns: *this.
basic_string& replace(const_iterator i1, const_iterator i2, basic_string_view<charT, traits> sv);
Requires: [begin(), i1) and [i1, i2) are valid ranges.
Effects: Calls replace(i1 - begin(), i2 - i1, sv).
Returns: *this.
basic_string& replace(const_iterator i1, const_iterator i2, const charT* s, size_type n);
Requires:[begin(), i1) and [i1, i2) are valid ranges and s points to an array of at least n elements of charT.
Effects: Calls replace(i1 - begin(), i2 - i1, s, n).
Returns: *this.
basic_string& replace(const_iterator i1, const_iterator i2, const charT* s);
Requires:[begin(), i1) and [i1, i2) are valid ranges and s points to an array of at least traits​::​​length(s) + 1 elements of charT.
Effects: Calls replace(i1 - begin(), i2 - i1, s, traits​::​length(s)).
Returns: *this.
basic_string& replace(const_iterator i1, const_iterator i2, size_type n, charT c);
Requires:[begin(), i1) and [i1, i2) are valid ranges.
Effects: Calls replace(i1 - begin(), i2 - i1, basic_­string(n, c)).
Returns: *this.
template<class InputIterator> basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2);
Requires:[begin(), i1), [i1, i2) and [j1, j2) are valid ranges.
Effects: Calls replace(i1 - begin(), i2 - i1, basic_­string(j1, j2, get_­allocator())).
Returns: *this.
basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<charT> il);
Requires:[begin(), i1) and [i1, i2) are valid ranges.
Effects: Calls replace(i1 - begin(), i2 - i1, il.begin(), il.size()).
Returns: *this.