string::insert

## `string::insert`

Insert characters at the specified index.

### Synopsis

    string&
    insert(
        std::size_t pos,
        string_view sv); (1)

    string&
    insert(
        std::size_t pos,
        std::size_t count,
        char ch); (2)

    string&
    insert(
        string::size_type pos,
        char ch); (3)

    template<
        class InputIt>
    string&
    insert(
        string::size_type pos,
        InputIt first,
        InputIt last); (4)

### Description

- (1) inserts `sv`.

- (2) inserts `count` copies of `ch`.

- (3) inserts the character `ch`.

- (4) inserts characters from the range `[first, last)`.

The first character is inserted at the index `pos`. All references, pointers, or iterators referring to contained elements are invalidated. Any past-the-end iterators are also invalidated.

### Constraints

`InputIt` satisfies LegacyInputIterator.

### Preconditions

`[first, last)` is a valid range.

### Exception Safety

- (1)–(3) strong guarantee.

- (4) strong guarantee if `InputIt` satisfies LegacyForwardIterator, basic guarantee otherwise.

### Template Parameters

Type | Description
--- | ---
`InputIt` | The type of the iterators.

### Return Value

`*this`

### Parameters

Name | Description
--- | ---
`pos` | The index to insert at.
`sv` | The `string_view` to insert.
`count` | The number of characters to insert.
`ch` | The character to insert.
`first` | The beginning of the character range.
`last` | The end of the character range.

### Exceptions

Type | Thrown On
--- | ---
`boost::system::system_error` | The size of the string would exceed `max_size()`.
`boost::system::system_error` | `pos >``size()`.

Edit this page