I tried to find out if try capture is needed in the following code:
std::vector<int> values;
values.push_back(1);
try {
for (std::vector<int>::iterator iter = values.begin();
iter != values.end(); ++iter) {
++(*iter);
}
} catch (const std::bad_alloc&) {
}
Looking through the C ++ 1998 standard, the only thing I can find is a hint at section 23.1, Container Requirements, which contains a sentence:
A copy of this argument is used for any performed memory allocation by these constructors and all member functions throughout the life cycle of each container object.
My interpretation is that any member function in a container can call a dispenser, so any member function can call std :: bad_alloc. Am I too paranoid or is it really so?
source
share