Thursday, April 1, 2010

Interesting Points about STL

In this post, I'll collect some interesting points about STL, knowing them may save me some time when the a strange problem appears.

1. The remove() algorithm is convenient sometimes. But be careful to know it does not change the number of elements in the container after some elements is "removed", it returns an iterator marking the new end.

2. Sometimes I may want to write a line of code like this: ++aCol.begin(), in this case I'm operating on a temporary variable, this is not alway allowed depending on the type of aCol and its implementation. First, modifying a temporary value of a fundamental type such as pointer is not allowed. The vector and string usually implement their iterator as a pointer, so if this is the case, ++aCol.begin() will not compile.

No comments: