[string.insert] (original) (raw)

27 Strings library [strings]

27.4 String classes [string.classes]

27.4.3 Class template basic_string [basic.string]

27.4.3.7 Modifiers [string.modifiers]

27.4.3.7.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.

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.

Throws:

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);

Constraints: InputIterator is a type that qualifies as an input iterator ([container.reqmts]).

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.

Preconditions: p is a valid iterator on *this.

Effects: Equivalent toinsert(p - begin(), basic_string(from_range, std​::​forward<R>(rg), get_allocator())).

Returns: An iterator which refers to the first inserted character, orp if rg is empty.

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

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