Insert iterators and insert container tab

I have been studying stl for the last two weeks and have been dealing with alot vector<T>, deque<T>and list<T>. All those times I used the push_back(), push_front(), insert(). Currently, I have been introduced to "Insert Iterators" , which are as follows:

  • back_insert_iteratorwhich is similar push_back()and requires that the container has a function push_back()to work
  • front_insert_iteratorwhich is similar push_front()and requires that the container haspush_front()
  • insert_iteratorsimilar insert()and blah blah blah

So, I know how to implement all this. My question is pretty simple, what's the difference? Why use Insert Iterators ?

+3
source share
1 answer

Because you can pass them to algorithms like

std::copy(v1.begin(), v1.end(), std::back_inserter(v2));
+9
source

All Articles