Nicolai M. Josuttis: solutions in time  The C++ Standard Library: Errata for 14th to 21st printings

The C++ Standard Library - A Tutorial and Reference

Errata for the 14th to 21st printings
Last update: August 30, 2011

This is the errata for the 14th to 21st printings of the book The C++ Standard Library by Nicolai M. Josuttis. It extends the errata for the previous printings. Thus, you will find additional errors in the erratas for later printings.
Please, note the
- hints for Visual C++ users.
- hints for GCC/G++ users.

The errata is organized in the following way:
- The first part lists technical errors
- The second part lists typos

Please note: This list may portray the book as containing many errors but keep in mind it has about 800 pages with about 240.000 words along with numerous tables and code examples. I am not perfect and it is unreasonable to expect significantly fewer bugs. To cite one reader: "Thanks again and I'm going to write a short review of the book for Amazon contradicting whoever said it had lots of errors."


Page 70, Section 4.5:
At the bottom, to be consistent, the code should define the operators also in namespace std::rel_ops:

namespace std {
  namespace rel_ops {
    template <class T1, class T2>
    inline bool operator!= (const T1& x, const T2& y) {
      return !(x == y);

Page 140, Section 5.11.2:
The auxiliary insert() function does not work because the last row always restores coll to its original contents. The function has to be implemented as follows:

 template <class T, class Cont, class Iter>
 void insert (Cont& coll, const Iter& pos, const T& value)
     Cont tmp(coll);             // copy container and all elements
     try {
         coll.insert(pos,value); // try to modify the copy
     catch (...) {               // in case of an exception
         coll.swap(tmp);         // - restore original container
         throw;                  // - and rethrow the exception

Page 141, Section 5.12:
When I write that "the STL is designed as a framework that may be extended in almost any direction," I should talk about one important way of extensibility that is not supported: The STL does not support public inheritance of its classes. For performance reasons no method is declared to be virtual. Thus, if you want to extend STL classes you should always wrap them by introducing them as members or use private inheritance.

Thus add at the end of page 141:

Note that all these extensions follow the principle of generic programming. That means, you can add new types that extend existing behavior by mapping it to something different. However, you can't extend behavior by simply inheriting container classes. For performance reasons all these classes have no virtual function and are therefore not provided for polymorphism through public inheritance. To add new behavior for containers you should define a new class that internally uses STL classes.

And, of course, an index entry for "STL and inheritance" would be appropriate.

Page 145, Section 6.1.2:
In Table 6.1 there is the following line missing:

c.erase(pos) | Removes the element at the position of iterator pos

Page 155, Section 6.2.3:
The C++ Standard Library does not state clearly whether the elements of
a vector are required to be in contiguous memory. However, it is the intention that this is guaranteed
and it will be fixed due to a defect report.
The C++ Standard Library guarantees that the elements of a vector are in contiguous memory.

Page 196, Section 6.6.2:
In Table 6.26 replace all occurences of Elem by Val (e.g.: map<Key,Elem> should be map<Key,Val>).

Page 230, Section 6.10.1
Type container::reverse_iterator is also provided by strings.

Page 273, Section 7.4.2
In iter/backins.cpp, the following include directive for class back_iterator is missing:

#include <iterator>

Page 274, Section 7.4.2
In iter/frontins.cpp, the following include directive for class front_iterator is missing:

#include <iterator>

Page 276, Section 7.4.2
In iter/inserter.cpp, the following include directive for class insert_iterator is missing:

#include <iterator>

Page 350, Section 9.5.3
In the declarations of find_end() there are iterators of different types involved. Thus, the declaration has to distinguish between ForwardIterator1 and ForwardIterator2:

find_end(ForwardIterator1 first1, ForwardIterator1 last1,
         ForwardIterator2 first2, ForwardIterator2 last2);
find_end(ForwardIterator1 first1, ForwardIterator1 last1,
         ForwardIterator2 first2, ForwardIterator2 last2,
         BinaryPredicate pred);

Page 352, Section 9.5.3
The return type of find_first_of() is ForwardIterator1 (twice).

Page 363, Section 9.6.1
The return type of copy_backward() is the type of the last argument:

copy_backward (BidirectionalIterator1 sourceBeg,
               BidirectionalIterator1 sourceEnd,
               BidirectionalIterator2 destEnd)

Page 382, Section 9.7.2
In the first bullet, replace op(elem,e) by op(e,elem).

Page 395, Section 9.8.5
The complexity of stable_partition is slightly different:

- For stable_partition(): linear if there is enough extra memory (numberOfElements calls of op() and swaps), or n-log-n otherwise (numberOfElements calls of op() but numberOfElement* log(numberOfElements) swaps)

Page 466, Section 10.4.2
For operators <<= and >>= for bitsets you should replace the last bullets as follows:

For <<=:

For >>=:

Page 471, Chapter 11
Saying that the type of string literals is const char* is not quite right. Strictly speaking, the original type of a literal such as "hello" is const char[6]. However, this type automatically converts ("decays") to const char*, so that you can almost always use (and see) const char* in declarations. However, when working with templates the difference might matter because for reference template parameters decay doesn't occur (see our template book ;-).

Page 514, Section 11.3.7
I left out the version of string::assign() that takes two InputIterator types, similar to the string::append() method you have on page 516:

string& string::assign (InputIterator beg, InputIterator end)

Page 734, Section 15.3
Due to the rules of dependent names of templates, the type definition of PtrAllocator needs an additional template (see Section 9.3.3 of our templates book ;-):

// rebind allocator for type T*
typedef typename Allocator:: template rebind<T*>::other PtrAllocator;

Page 747, Index


Note: Page numbers in bold indicate the location of the definition of the
item. Page numbers in the normal type face are other pages of interest. If
the entry appears in source code the page numbers are in the italic type

Page 743, Internet Resources

The current version of the C++ Standard is the document ISO/IEC 14882-2003. You can get it as PDF file at for $ 30.00.

Thus, replace: "... at the Electronic Standard Store of ANSI for $18 (US) at the following site:"
by: "... at the Standards Store of ANSI for $30 (US) at the following site (look for document number 14882):"

See the FAQ for details.


Page 26: s/It does this by using the function unexpected(). unexpected() is called /It can be thrown by the function unexpected(), which is called /

Page 46, first line: s/ClassB (ClassA val1, ClassA val2)/ClassB (const ClassA& val1, const ClassA& val2)/

Page 52: s/Constructors, Assignments, and Destructors/Constructors, Assignments, and Destructor/

Page 61: s/number of nonsigned bits/number of bits excluding sign/

Page 75, s/for arbitrary types and classes respectively/for arbitrary types and classes, respectively/

Page 99, s/(see Section 2, page 93, and/(see Section 5.3.2, page 93, and/

Page 113: s/print number of resulting elements/print number of removed elements/

Page 123: s/example sorts elements of a set/example sorts elements of a deque/

Page 150, Table 6.2: s/c.~vector<Elem>()/c.~vector()/

Page 162, Table 6.9: s/c.~deque<Elem>()/c.~deque()/

Page 167, Table 6.12: s/c.~list<Elem>()/c.~list()/

Page 176: s/following three properties:/following four properties:/

Page 180:  c. is missing in front of all operation in Table 6.22

Page 182: s/the with following arguments/with the following elements/

Page 189: s/looks a bit differently/looks a bit different/

Page 199:  c. is missing in front of all operation in Table 6.28

Page 200: s/with the following arguments/with the following elements/

Page 231: s/The type of the value of the elements/The type of the value part of the elements/

Page 327, Table 9.5: s/Same as partition() but/Same as partition(), but/

Page 328, Table 9.6: s/Same as partition() but/Same as partition(), but/

Page 368: s/to the the destination range/to the destination range/

Page 376: s/[beg,end)/[sourceBeg,sourceEnd)/ (twice)

Page 380: s/[beg,end)/[sourceBeg,sourceEnd)/ (twice)

Page 389, rotate_copy(): s/so that newBeg is the new first element/so that *newBeg is the new first element/

Page 391, next_permutation(): s/CompFunc op /BinaryPredicate op/ (twice)
Page 391, prev_permutation(): s/CompFunc op /BinaryPredicate op/ (twice)

Page 391: s/Both algorithms return false if the elements have the "normal'' (lexicographical) order;/Both algorithms return false if the elements got the "normal'' (lexicographical) order;/

Page 406: s/RandomAccesIterator/RandomAccessIterator/ (eight times)
Page 407: s/
RandomAccesIterator/RandomAccessIterator/ (eight times)

Page 409: s/Sorted Range Algorithms/Sorted-Range Algorithms/
Page 409: s/
Sorted range Algorithms/Sorted-range Algorithms/
Page 409: s/
element-by-element/element by element/

Page 450, Listing: s/exception class for pop() and top()/exception class for pop() and front()/

Page 451: s/read element from the queue and return its value/remove next element from the queue and return its value/

Page 452: s/read and print two elements from the queue/pop two elements from the queue and print their value/

Page 478, 2nd paragraph: s/returns the first character that is not part/returns the position of the first character that is not part/

Page 482, Table 11.2: s/size_type num/size_type num/ (just the font)

Page 483: s/11.2.3 Constructors and Destructors/11.2.3 Constructors and Destructor/

Page 483: s/Table 11.4 lists all constructors and destructors for strings./Table 11.4 lists all constructors and the destructor for strings./

Page 487: s/Both return the character at the position/Both return a reference to the character at the position/

Page 520: s/(iterator beg, iterator end/(iterator beg, iterator end,/

Page 537: s/an add hoc criterion/an ad hoc criterion/

Page 610: s/The differenc between ungetc()/The difference between unget()/

Page 638: s/cerr.tie (&cout);/std::cerr.tie (&std::cout);/

Page 719: s/equivalent to isalpha()&&isdigit()/equivalent to isalpha()||isdigit()/

Page 719: s/equivalent to isalnum()&&ispunct()/equivalent to isalnum()||ispunct()/

Home of the C++ Library book