[string.insert] (original) (raw)

21 Strings library [strings]

21.3 String classes [string.classes]

21.3.2 Class template basic_­string [basic.string]

21.3.2.6 Modifiers [string.modifiers]

21.3.2.6.4 basic_­string​::​insert [string.insert]

constexpr basic_string& insert(size_type pos, const basic_string& str);

Effects:Equivalent to: return insert(pos, str.data(), str.size());

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

Effects:Equivalent to:

return insert(pos1, basic_string_view<charT, traits>(str), pos2, n);

template<class T> constexpr basic_string& insert(size_type pos, const T& t);

Constraints:

Effects:Equivalent to:

basic_string_view<charT, traits> sv = t; return insert(pos, sv.data(), sv.size());

template<class T> constexpr basic_string& insert(size_type pos1, const T& t, size_type pos2, size_type n = npos);

Constraints:

Effects:Equivalent to:

basic_string_view<charT, traits> sv = t; return insert(pos1, sv.substr(pos2, n));

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

Preconditions: [s, s + n) is a valid range.

Throws:

Effects:Inserts a copy of the range [s, s + n)immediately before the character at position pos if pos < size(), or otherwise at the end of the string.

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

Effects:Equivalent to: return insert(pos, s, traits​::​length(s));

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

Effects:Inserts n copies of c before the character at position posif pos < size(), or otherwise at the end of the string.

Throws:

constexpr iterator insert(const_iterator p, charT c);

Preconditions: p is a valid iterator on*this.

Effects:Inserts a copy of c at the position p.

Returns:An iterator which refers to the inserted character.

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

Preconditions: p is a valid iterator on*this.

Effects:Inserts n copies of c at the position p.

Returns:An iterator which refers to the first inserted character, orp if n == 0.

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

Preconditions: p is a valid iterator on*this.

Effects:Equivalent toinsert(p - begin(), basic_­string(first, last, get_­allocator())).

Returns:An iterator which refers to the first inserted character, orp if first == last.

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

Effects:Equivalent to: return insert(p, il.begin(), il.end());