Class back_insert_iterator

Synopsis

#include <include/EASTL/iterator.h>

template <typename Container>
class back_insert_iterator : public iterator<EASTL_ITC_NS::output_iterator_tag, void, void, void, void>

Description

back_insert_iterator

A back_insert_iterator is simply a class that acts like an iterator but when you assign a value to it, it calls push_back on the container with the value.

Mentioned in

Inheritance

Ancestors: iterator

Methods

back_insert_iterator: container(x.container) { }
operator*
operator++ overload
operator= overload

Source

Lines 607-644 in include/EASTL/iterator.h.

template <typename Container>
class back_insert_iterator : public iterator<EASTL_ITC_NS::output_iterator_tag, void, void, void, void>
{
public:
    typedef back_insert_iterator<Container>     this_type;
    typedef Container                           container_type;
    typedef typename Container::const_reference const_reference;
protected:
    Container& container;
public:
    //back_insert_iterator(); // Not valid. Must construct with a Container.
    //back_insert_iterator(const this_type& x) // Compiler-implemented
    //    : container(x.container) { }
    explicit back_insert_iterator(Container& x)
        : container(x) { }
    back_insert_iterator& operator=(const_reference value)
        { container.push_back(value); return *this; }
    back_insert_iterator& operator=(typename Container::value_type&& value)
        { container.push_back(eastl::move(value)); return *this; }
    back_insert_iterator& operator*()
        { return *this; }
    back_insert_iterator& operator++()
        { return *this; } // This is by design.
    back_insert_iterator operator++(int)
        { return *this; } // This is by design.
protected:
    void operator=(const this_type&){} // Declared to avoid compiler warnings about inability to generate this function.
};





Add Discussion as Guest

Log in