21 Strings library [strings]

21.4 Class template basic_string [basic.string]

21.4.6 basic_string modifiers [string.modifiers]

21.4.6.4 basic_string::insert [string::insert]

basic_string& insert(size_type pos1, const basic_string& str);

Requires: pos <= size().

Throws: out_of_range if pos > size().

Effects: Calls insert(pos, str.data(), str.size()).

Returns: *this.

basic_string& insert(size_type pos1, const basic_string& str, size_type pos2, size_type n = npos);

Requires: pos1 <= size() and pos2 <= str.size()

Throws: out_of_range if pos1 > size() or pos2 > str.size().

Effects: Determines the effective length rlen of the string to insert as the smaller of n and str.size() - pos2 and calls insert(pos1, str.data() + pos2, rlen).

Returns: *this.

basic_string& insert(size_type pos, const charT* s, size_type n);

Requires: s points to an array of at least n elements of charT and pos <= size().

Throws: out_of_range if pos > size() or length_error if size() + n > max_size().

Effects: Replaces the string controlled by *this with a string of length size() + n whose first pos elements are a copy of the initial elements of the original string controlled by *this and whose next n elements are a copy of the elements in s and whose remaining elements are a copy of the remaining elements of the original string controlled by *this.

Returns: *this.

basic_string& insert(size_type pos, const charT* s);

Requires: pos <= size() and s points to an array of at least traits::length(s) + 1 elements of charT.

Effects: Equivalent to insert(pos, s, traits::length(s)).

Returns: *this.

basic_string& insert(size_type pos, size_type n, charT c);

Effects: Equivalent to insert(pos, basic_string(n, c)).

Returns: *this.

iterator insert(const_iterator p, charT c);

Requires: p is a valid iterator on *this.

Effects: inserts a copy of c before the character referred to by p.

Returns: An iterator which refers to the copy of the inserted character.

iterator insert(const_iterator p, size_type n, charT c);

Requires: p is a valid iterator on *this.

Effects: inserts n copies of c before the character referred to by p.

Returns: An iterator which refers to the copy of the first inserted character, or p if n == 0.

template<class InputIterator> iterator insert(const_iterator p, InputIterator first, InputIterator last);

Requires: p is a valid iterator on *this. [first,last) is a valid range.

Effects: Equivalent to insert(p - begin(), basic_string(first, last)).

Returns: An iterator which refers to the copy of the first inserted character, or p if first == last.

iterator insert(const_iterator p, initializer_list<charT> il);

Effects: insert(p, il.begin(), il.end()).

Returns: An iterator which refers to the copy of the first inserted character, or p if i1 is empty.