1

If i have:

std::list<int> mylist = { 3 };
auto it = mylist.begin();

but i start to do a lot of adds:

mylist.insert(it, 5); mylist.insert(it, 7);

is there any possibility that it could be breaked? (for example, by realocation of the std::list) what about push_back? can this other function make a pointer invalid?

1 Answers1

0

There's no reallocation for std::list; insert won't invalidate any iterators, and same for push_back.

No iterators or references are invalidated.

songyuanyao
  • 169,198
  • 16
  • 310
  • 405
  • so, if a `std::list` has only 2 spaces internally, how are those iterators never breaked? – Franz Kafka Oct 08 '20 at 05:22
  • 1
    *`std::list` has only 2 spaces internally*, `std::list` doesn't have such concepts, it is usually implemented as a doubly-linked list; it's not `std::vector`. – songyuanyao Oct 08 '20 at 05:26