June 2007
Intermediate to advanced
624 pages
15h 14m
English
Correctness must be a local property. | ||
| --Neils Ferguson and Bruce Schneier | ||
It pays to be obvious, especially if you have a reputation for subtlety. | ||
| --Isaac Asimov | ||
As described in Section 1.2, the different standard containers have various rules for when and how their iterators (and pointers and references) may be invalidated in response to mutating changes on them. For example, in the following code, both b and e are invalidated:
std::vector<int> ints; ints.push_back(1); ints.push_back(2); std::vector<int>::iterator b = ints.begin(); std::vector<int>::iterator e = ints.end(); ints.erase(b); // b and e are invalidated
That’s because the standard dictates that all iterators of ...
Read now
Unlock full access