Examples and Notes Based on "Effective STL"

Item5.cpp illustrates the use of the assign function, within the STL container classes. It uses the boost timer class to time copies with the assign operator, and compares the timing to the equivalent for loop. It also illustrates the use of the ostream_iterator to write to cout.

Item6.cpp illustrates the use of istream_iterator, and ostream_iterator

Item7.cpp illustrates the use of the for_each template function and the template function unary_function, to delete a vector of pointers.

Item7a.cpp illustrates the use of the smart_ptr class from boost, to do the same thing as Item7.cpp .

Item8.cpp illustrates an illegal use of the auto_ptr class. This won't compile under gcc. It shouldn't compile under any compiler, but some compilers are mistaken. It is a bad idea to use auto_ptr's in containers because, the equal operator causes the rhs to loose ownership of its object. Thus a temporary variable, initalized from an object in a container will destroy the object pointered to by the intial object, when it goes out of scope.

Item8a.cpp illustrates the use of the sort function, on the array from Item7a.cpp.