[insert.iterator]

# 24 Iterators library [[iterators]](./#iterators)

## 24.5 Iterator adaptors [[predef.iterators]](predef.iterators#insert.iterator)

### 24.5.2 Insert iterators [[insert.iterators]](insert.iterators#insert.iterator)

#### 24.5.2.4 Class template insert_iterator [insert.iterator]

#### [24.5.2.4.1](#insert.iter.general) General [[insert.iter.general]](insert.iter.general)

[ð](#lib:insert_iterator)

namespace std {template<class Container>class insert_iterator {protected: Container* container;
 ranges::iterator_t<Container> iter; public:using iterator_category = output_iterator_tag; using value_type = void; using difference_type = ptrdiff_t; using pointer = void; using reference = void; using container_type = Container; constexpr insert_iterator(Container& x, ranges::iterator_t<Container> i); constexpr insert_iterator& operator=(const typename Container::value_type& value); constexpr insert_iterator& operator=(typename Container::value_type&& value); constexpr insert_iterator& operator*(); constexpr insert_iterator& operator++(); constexpr insert_iterator& operator++(int); };}

#### [24.5.2.4.2](#insert.iter.ops) Operations [[insert.iter.ops]](insert.iter.ops)

[ð](#lib:insert_iterator,constructor)

`constexpr insert_iterator(Container& x, ranges::iterator_t<Container> i);
`

[1](#insert.iter.ops-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L4090)

*Effects*: Initializescontainer with addressof(x) anditer with i[.](#insert.iter.ops-1.sentence-1)

[ð](#lib:operator=,insert_iterator)

`constexpr insert_iterator& operator=(const typename Container::value_type& value);
`

[2](#insert.iter.ops-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L4105)

*Effects*: As if by:iter = container->insert(iter, value);++iter;

[3](#insert.iter.ops-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L4113)

*Returns*: *this[.](#insert.iter.ops-3.sentence-1)

[ð](#lib:operator=,insert_iterator_)

`constexpr insert_iterator& operator=(typename Container::value_type&& value);
`

[4](#insert.iter.ops-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L4124)

*Effects*: As if by:iter = container->insert(iter, std::move(value));++iter;

[5](#insert.iter.ops-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L4132)

*Returns*: *this[.](#insert.iter.ops-5.sentence-1)

[ð](#lib:operator*,insert_iterator)

`constexpr insert_iterator& operator*();
`

[6](#insert.iter.ops-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L4143)

*Returns*: *this[.](#insert.iter.ops-6.sentence-1)

[ð](#lib:operator++,insert_iterator)

`constexpr insert_iterator& operator++();
constexpr insert_iterator& operator++(int);
`

[7](#insert.iter.ops-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L4155)

*Returns*: *this[.](#insert.iter.ops-7.sentence-1)

#### [24.5.2.4.3](#inserter) inserter [[inserter]](inserter)

[ð](#lib:inserter)

`template<class Container>
  constexpr insert_iterator<Container>
    inserter(Container& x, ranges::iterator_t<Container> i);
`

[1](#inserter-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L4170)

*Returns*: insert_iterator<Container>(x, i)[.](#inserter-1.sentence-1)
