Reference Survives Push Front
std::deque<int> d{1, 2, 3};
int& rd = d[1];
d.push_front(0);
std::cout << rd << " "; // (1)
std::vector<int> v{1, 2, 3}; // capacity == 3
int& rv = v[1];
v.push_back(4);
std::cout << rv << "\n"; // (2)
Which line, if either, is undefined behaviour?
Sign in to answer questions and track your progress
Sign In