简体   繁体   中英

Insert Iterators vs container's member function inserter

I've been studying stl for the past two weeks and been dealing with alot of vector<T> , deque<T> , and list<T> . All those times I've been using push_back() , push_front() , insert() . Currently though, I've been introduced to "Insert Iterators" which are the following:

  • back_insert_iterator , which is similar to push_back() and does requires the container to have a push_back() function to work
  • front_insert_iterator , which is similar to push_front() and requires the container to have a push_front()
  • insert_iterator , similar insert() and blah blah blah

So I know how to implement all of this. My question is quite simple, what is the difference? Why bother using the Insert Iterators ?

因为你可以将它们传递给算法,例如

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM