C ++: behavior of push_back () and back () with pointers

I have two C ++ lists, std::list<T> List1 and std::list<T*> List2; . Now I would like to do the following operation several times:

 List1.push_back(new_object); List2.push_back(&List1.back()); 

My question is: is the link stored in List2 after each step? Ie: Does the first item in List2 still refer to the first in List1, etc.?

+5
source share
1 answer

Yes, it remains valid. std::list Insertion does not cancel iterators (or pointers to contents in this case).

+9
source

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


All Articles