---
name: "std::insert_iterator"
section: "3"
platform: "linux"
package: "gcc"
version: "16.2.1+r23+gd564253eb6c8-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/std::insert_iterator"
---

# std::insert\_iterator(3)

Turns assignment into insertion.

## NAME

std::insert\_iterator\< \_Container \> - Turns assignment into insertion.

## SYNOPSIS

\#include \<iterator\>

Inherits **std::iterator\< output\_iterator\_tag, void, void, void, void \>**.

### Public Types

typedef \_Container **container\_type**\
 A nested typedef for the type of whatever container you used.  using **difference\_type**\
 typedef **output\_iterator\_tag** **iterator\_category**\
 One of the **tag types**.  typedef void **pointer**\
 This type represents a pointer-to-value\_type.  typedef void **reference**\
 This type represents a reference-to-value\_type.  typedef void **value\_type**\
 The type *pointed*to"*by*the*iterator.*

### Public Member Functions

constexpr **insert\_iterator** (\_Container &\_\_x, \_Iter \_\_i)\
 constexpr **insert\_iterator** & **operator\*** ()\
 Simply returns \*this.  constexpr **insert\_iterator** & **operator++** ()\
 Simply returns \*this. (This iterator does not *move*.).  constexpr **insert\_iterator** & **operator++** (int)\
 Simply returns \*this. (This iterator does not *move*.).  constexpr **insert\_iterator** & **operator=** (const typename \_Container::value\_type &\_\_value)\
 constexpr **insert\_iterator** & **operator=** (typename \_Container::value\_type &&\_\_value)\

### Protected Attributes

\_Container \* **container**\
 \_Iter **iter**\

## Detailed Description

### template\<typename \_Container\>

class std::insert\_iterator\< \_Container \>"Turns assignment into insertion.

These are output iterators, constructed from a container-of-T. Assigning a T to the iterator inserts it in the container at the iterator's position, rather than overwriting the value at that position.

(Sequences will actually insert a *copy* of the value before the iterator's position.)

Tip: Using the inserter function to create these iterators can save typing.

## Member Typedef Documentation

### template\<typename \_Container\> typedef \_Container std::insert\_iterator\< \_Container \>::container\_type

A nested typedef for the type of whatever container you used.

### typedef output\_iterator\_tag std::iterator\< output\_iterator\_tag, void, void, void, void \>::iterator\_category \[inherited\]

One of the **tag types**.

### typedef void std::iterator\< output\_iterator\_tag, void, void, void, void \>::pointer \[inherited\]

This type represents a pointer-to-value\_type.

### typedef void std::iterator\< output\_iterator\_tag, void, void, void, void \>::reference \[inherited\]

This type represents a reference-to-value\_type.

### typedef void std::iterator\< output\_iterator\_tag, void, void, void, void \>::value\_type \[inherited\]

The type "pointed to" by the iterator.

## Constructor & Destructor Documentation

### template\<typename \_Container\> std::insert\_iterator\< \_Container \>::insert\_iterator (\_Container & \_\_x, \_Iter \_\_i) \[inline\], \[constexpr\]

The only way to create this iterator is with a container and an initial position (a normal iterator into the container).

References **std::\_\_addressof()**.

## Member Function Documentation

### template\<typename \_Container\> insert\_iterator & std::insert\_iterator\< \_Container \>::operator\* () \[inline\], \[nodiscard\], \[constexpr\]

Simply returns \*this.

### template\<typename \_Container\> insert\_iterator & std::insert\_iterator\< \_Container \>::operator++ () \[inline\], \[constexpr\]

Simply returns \*this. (This iterator does not *move*.).

### template\<typename \_Container\> insert\_iterator & std::insert\_iterator\< \_Container \>::operator++ (int ) \[inline\], \[constexpr\]

Simply returns \*this. (This iterator does not *move*.).

### template\<typename \_Container\> insert\_iterator & std::insert\_iterator\< \_Container \>::operator= (const typename \_Container::value\_type & \_\_value) \[inline\], \[constexpr\]

**Parameters**

*\_\_value* An instance of whatever type container\_type::const\_reference is; presumably a reference-to-const T for container\<T\>.

**Returns**

This iterator, for chained operations.

This kind of iterator maintains its own position in the container. Assigning a value to the iterator will insert the value into the container at the place before the iterator.

The position is maintained such that subsequent assignments will insert values immediately after one another. For example,

```
// vector v contains A and Z
insert_iterator i (v, ++v.begin());
i = 1;
i = 2;
i = 3;
// vector v contains A, 1, 2, 3, and Z
```

## Author

Generated automatically by Doxygen for libstdc++ from the source code.
