Code Fixes for the STL Tutorial and Reference Guide

SE 598 - Data Structures and Algorithms, Summer 2000


The STL Tutorial and Reference Guide by Musser and Saini was published before the STL library was accepted as part of ANSI-ISO standard C++. Inbetween publication and acceptance the STL has changed from what was described the STL Tutorial. The changes to the STL are not significant, but do render uncompilable some of the code given in the STL Tutorial.

This page describes the code that is effected by the STL changes, and describes changes to the code to make it compilable under the current STL. Unless otherwise noted, each problem described below was reproduced under Solaris 2.7 using g++ version 2.95.2 and under DEC Unix 5.0 using cxx version 6.2-024; each fix was also verified under the same two systems.

Now for the caveats:

Page 155:
#include<multiset.h>

The multiset class is defined in <set>.

#include<set>

Page 195:
vector<char> word = *j;

There is apparently no longer a conversion from a string to a vector of characters. Replace it with iterators over the string:

vector<char> word((*j).begin(), (*j).end());

Page 196:
binary_search(dictionary.begin(), dictionary.end(), string(word))

The conversion from a vector of characters to a string has also gone missing; replace it with the iterator-range constructor for strings:

binary_search(dictionary.begin(), dictionary.end(), string(word.begin(), word.end()))

Page 203:
PS(const string& s) : pair<vector<char>,string>(s, s) {

No conversion from string to a vector of characters defined; use the iterator-range constructor for vectors.

PS(const string& s) : pair<vector<char>,string>(vector<char>(s.begin(), s.end()), s) {

Page 204:
Add <functional> to the list of include files.

Page 205:
vector<PS>::const_iterator k = find_if(j + 1, finis, not1(bind1st(firstEqual, *j)))

The constant iterator k is not type-compatible in either the copy or the assignment to j. Define k as a non-constant iterator (or cast each occurence of k to vector<PS>::iterator, but then what's the point of the declaration).

vector<PS>::iterator k = find_if(j + 1, finis, not1(bind1st(firstEqual, *j)))

Page 231:
The Gnu g++ compiler required that the iterator_category, value_type, difference_type, pointer, and reference typedefs be defined in the counting-iterator class. The DEC gxx compiler didn't require these typedefs, but it accepted them as part of the counting-iterator class.

typedef forward_iterator_tag iterator_category;
typedef T value_type;
typedef int difference_type;
typedef T* pointer;
typedef T& reference;

Page 233:
Traversing array x 
 from i (Curly) to end (Larry). 
12 
4 
The output from the test program differs from what's given in the book (and the output when the program is compiled by g++ differs from the output when the program is compiled by gxx). This may not be an error, just a difference in the way various constructs are implemented by the two compilers.

Traversing array x 
 from i (Curly) to end (Larry). 
12 
Copying Curly, new version is 2. 
4 


This page last modified on 1 August 2000.