2 ms·
Interestingly, the dangers of reference invalidation is actually one of the reasons why auto doesn't deduce references by default: vector<int> v = {42};
by gpderetta 5y ago
Interestingly, the dangers of reference invalidation is actually one of the reasons why auto doesn't deduce references by default:
vector<int> v = {42};
...
auto x = v[0]
v.clear();
// if x was deduced as reference, using x at this point
// would be UB
std::cout<< x;