Junior — Senior
Behavior of the saved iterator after changing the container
livecode
Task condition
Investigate how an iterator obtained before modifying a container behaves when subsequently used with different STL containers (for example, std::list and std::vector).
template<typename C>
void process(C& container) {
container.push_back(0);
auto it = container.begin();
for (size_t i = 1u; i < 1000u; ++i) {
container.push_back(i);
}
std::cout << "First: " << *it << std::endl;
}
int main(int argc, char** argv) {
std::list<int> lst;
process(lst);
std::vector<int> vec;
process(vec);
return EXIT_SUCCESS;
}