How to insert iterator operation in C ++

there is an insert iterator in the database template library or in another library, can someone tell me how this works? Thanks!

+3
source share
1 answer

This is a class of templates so you can find it in the implementation.

However, the idea is that it stores an iterator (current location) and a link (pointer) to the container (which is inserted). Then it overloads operator = as follows:

insert_iterator& operator= (typename Container::const_reference value)
{
    m_iter = m_container->insert(m_iter, value);
    ++m_iter;
    return *this;
}

Therefore, this requires a container that supports the insertion method and at least a direct iterator and has standard typesdefs (const_reference or, possibly, value_type), so it can declare the right type of its = operator.

(*, ++) * this.

+3

Source: https://habr.com/ru/post/1717553/


All Articles