Search This Blog

Friday, May 13, 2011

ExceptionalC++ Fun: 1. iterators

Things to remember:
  1. check if the iterator can be differentiated.  e.g. don't do *iterator.end()
  2. check if the iterator is still validated. e.g. after inserting or removing elements. it invalidates reference, pointers, and iterators that refer to the following elements
  3. check if the iterator is in range. e.g. first does not pass end, or itor1 and itor2 should belong to the same container. 
  4. check if operation on iterator does not manipulate the temporary of built in type (c++ does not allow it). e.g. --itor.end() as a function argument(become temporary) might be an error. WHY???

No comments: