Share via


insert_iterator

insert_iterator

template<class Cont>
    class insert_iterator
        : public iterator<output_iterator_tag, void, void> {
public:
    typedef Cont container_type;
    typedef Cont::value_type value_type;
    explicit insert_iterator(Cont& x, Cont::iterator it);
    insert_iterator& operator=(const Cont::value_type& val);
    insert_iterator& operator*();
    insert_iterator& operator++();
    insert_iterator& operator++(int);
protected:
    Cont& container;
    Cont::iterator iter;
    };

The template class describes an output iterator object. It inserts elements into a container of type Cont, which it accesses via the protected reference object it stores called container. It also stores the protected iterator object, of class Cont::iterator, called iter. The container must define:

  • The member type iterator, which is the type of an iterator for the container.
  • The member type value_type, which is the type of an element of the sequence controlled by the container.
  • The member function insert``(iterator it, value_type c), which inserts a new element with value c immediately before the element designated by it in the controlled sequence, then returns an iterator that designates the inserted element.