REVIEW - The C++ Standard Template Library


Title:

The C++ Standard Template Library

Author:

P. J. Plauger

ISBN:

Publisher:

Prentice Hall (2001)

Pages:

485pp

Reviewer:

Andrei Iltchenko

Reviewed:

April 2001

Rating:

★☆☆☆☆


This is probably the first book on STL that presents the source code of one real implementation of that part of the Standard C++ library to the reader. To make the book yet more attractive to buy the author says in the Preface "You will find here a complete presentation of STL as it is specified by the C++ Standard. ... We present about 6,000 lines of tested, working code that is known to be portable across a number of C++ compilers. ... Minor changes have been made in formatting and notation, to make the book form of the code more readable and tutorial. ... The code in this book... It passes all the STL tests in the Dinkum C++ Proofer and the Dinkum Abridged Proofer, both quality-assurance tools for the corresponding libraries available commercially from Dinkumware, Ltd".

Having read such promising statements a prospective buyer starts to firmly believe that the code and the accompanying explanations presented are indeed based on the latest ISO/IEC C++ Standard, and that the source code in the book is fairly easy to read. Let's find out what the book really has to offer.

First of all, the book assumes a rather advanced knowledge of C++, and it scarcely discusses any technicalities involved. The book consists of 16 chapters besides the introduction, each of which covers one particular aspect of STL Iterators, utility, iterator, memory, Algorithms, algorithm, numeric, functional, Containers, vector, list, deque, set, map, stack, and queue. Each chapter can be divided into 6 parts 1. Background, 2. Functional Description (merely a reference of the relevant STL components), 3. Using, 4. Implementing, 5. Testing, 6. Exercises. With the minor exception of the explanatory chapters "Iterators", "Algorithms", and "Containers" that lack the sections "Implementing" and "Testing".

It should be noted that all the sections named "Functional Descriptions" are almost the same as what you can find athttp://www.dinkumware.com/htm_cpl/index.html. The depth of explanation is certainly the same.

The sections called "Background" are usually 2-4 pages long and contain some general explanation of the component. The sections called "Using" are also short, about two pages each and serve to supplement what information was given in the corresponding "Functional Descriptions".

"Testing" contains a small program, usually 3 pages long, that runs a few superficial tests. "Exercises" presents a reader with a number of questions and tasks, some of which are really time-consuming and difficult. There are no solutions to the exercises nor any clues as to how to tackle them best or what they are doing in a reference book.

"Implementing" contains the source code itself (which occupies a good deal of the book) with 3-5 pages of comments that follow the code. There are absolutely no comments in the code itself! Although the book sets the goal of presenting the source code of STL, it doesn't contain a single figure to help the reader understand what the code does. So those of you who've grown accustomed to Richard W. Stevens's depth and quality of presenting source code will be disappointed. The lack of figures is especially obvious when the book describes such non-trivial data structures as red-black trees or the various sorting algorithms. You have to take a piece of paper and start drawing your own figures as you go through the code with the purpose of understanding it. The scanty cursory comments follow the code are definitely not enough to help you assimilate the code given in a short time, so you are really left on your own. To make things yet more difficult the author uses a really off-the-wall coding style, which a lot of readers will have a hard time getting used to. See the figure for an example of the code

The most unsatisfactory thing about the book is that its contents deviate from what the Standard says and, what is dangerous, it authoritatively miss-states things. For example the book claims that

1. "For all the container classes defined by STL, if an exception is thrown during calls to the following member functions insert (single element insert), push_back, push_front the container is left unaltered and the exception is rethrown". Whereas the C++ Standard gives such strong guarantee for the overloaded member functions insert of classes vector and deque only on condition that the copy constructor and the copy assignment operator of the type T used to instantiate the container do not throw while inserting, see 23.2.1.3/2 and 23.2.4.3/1 of the Standard.

2. "For all the container classes defined by STL, no exception is thrown during calls to the following member functions erase (single element erase), pop_back, pop_front". Again the book fails to acknowledge that the C++ Standard gives the no-throw guarantee for the overloaded member functions erase of classes vector and deque only on condition that the copy constructor and the copy assignment operator of the type T used to instantiate the container do not throw while erasing, see 23.2.1.3/6 and 23.2.4.3/5 of the Standard.

The above over-confident statements could be partially justified, had the STL part of Dinkumware's Standard C++ library presented in the book delivered what the book claims. But, having studied the code of vector and deque, I can say that is not the case.

3. "The member function swap makes additional promises for all container classes defined by STL the member function throws an exception only if the container stores an allocator object al, and al throws an exception when copied". That's another mistake, for the Standard promises something completely different "no swap function throws an exception unless that exception is thrown by the copy constructor or assignment operator of the container's Compare object" (23.1/10).

On top of that, the code presented in the book is not even slightly compatible with the Standard exception-wise, not to mention a few major bugs in almost every container presented. For instance, almost every constructor of the class template vector leaks memory if the copy constructor of the user-supplied type T used to instantiate the container throws an exception. You can study a discussion on the above issue at the news group comp.lang.c++.moderated, the initial message was called "BUGS in Dinkumware STL and the new book by Plauger on the C++ STL".


Book cover image courtesy of Open Library.





Your Privacy

By clicking "Accept Non-Essential Cookies" you agree ACCU can store non-essential cookies on your device and disclose information in accordance with our Privacy Policy and Cookie Policy.

Current Setting: Non-Essential Cookies REJECTED


By clicking "Include Third Party Content" you agree ACCU can forward your IP address to third-party sites (such as YouTube) to enhance the information presented on this site, and that third-party sites may store cookies on your device.

Current Setting: Third Party Content EXCLUDED



Settings can be changed at any time from the Cookie Policy page.