Answer»
- Understand MEMBER functions size(), max_size() and resize().
- Understand member functions begin(), end(), rbegin() and rend().
- Understand the fact that a reference to a "range" of values in STL generally means those values from (and including) the first value in the range up to (but not including) the LAST value in the range. Such a range can extend forward or backward, depending on the kinds of iterators being used.
- Even though it may (SOMETIMES) work, it is better not use a loop like for (i = c.begin(); i < c.end(); i++) ... for processing all the elements of a container c; it is preferable INSTEAD to use a loop like this: for (i = c.begin(); i != c.end(); i++) ... This second form is often necessary, in fact, since not all container iterators support operator<.
- RIt is safest to assume that insert() applied to a deque or a vector will invalidate any iterators or references to elements of the deque or vector.
- Know that any insert() member function applied to a container may (or may not) invalidate iterators and references already pointing at elements of that container.
In particular:
- It is safest to assume that insert() applied to a deque or a vector will invalidate any iterators or references to elements of the deque or vector.
- On the other hand, insert() applied to any of the other first-class containers (list, map, multimap, set, multiset) does not invalidate any of the iterators or references to elements of the container, and deletions from these containers invalidate only iterators or references to the elements deleted.
- Remember that if you are using the STL for a given purpose in a situation that requires (as a minimal requirement) that a certain kind of iterator be used, a more powerful iterator may also be used in that situation
- Remember that if you have the choice between using an STL algorithm and using an STL container class method to accomplish the same purpose, you should PREFER the class method.
- Know that any container that is the target of an algorithm must be large enough to hold all elements it will receive, since it will not automatically be increased in size. Or, plan to use an inserter.
In particular:
|