Book Reviews


The C++ Standard Library: A Tutorial and Reference

reviewed by Ben Forshaw


Title:The C++ Standard Library:
A Tutorial and Reference
Author:Nicolai M. Josuttis
Publisher:Addison Wesley Longman, Inc., 1999
Pages:800
ISBN:0-201-37926-0
Price:$49.95 U.S.

Introduction

This book is one of those rare volumes whose contents are summed up precisely by its title. It covers virtually the whole of the C++ Standard library; it explains the concepts and motivation behind library features before describing their implementation and usage. The word "standard" is important here: this book was finished after the publication of the language standard and is up to date with respect to that document.

Josuttis has written a book that will be of value to anybody using C++ today. As a tutorial, it will explain and demonstrate the library to those readers who have little or no experience of it. It may be read from cover to cover: I certainly discovered library features of whose existence I had not previously been aware. But it is as a reference that this book will earn its long-term place by the side of any C++ programmer.

The Book

The author begins by outlining the book itself and briefly describing each of its chapters. He continues with a brief history of the library’s development and a discussion of the language features that evolved in parallel: templates, namespaces, and exceptions among others. The treatment of the library itself is largely sequential. From the foundations of namespace std and the std::exception class hierarchy, he progresses through general utilities like std::pair before arriving at the STL, which he describes as "the heart of the C++ Standard library."

The STL is probably the most influential part of the library, in terms of changing the way we write C++ programs. The first, introductory chapter on the STL concerns itself with architecture and motivation. The generic programming paradigm is presented and contrasted with OO. The trinity of Containers, Iterators and Algorithms are introduced and their relationships to each other clearly explained using examples to illustrate key points. Having provided the background, Josuttis goes on to describe the STL classes and functions themselves. Containers, iterators, functions, and algorithms each get their own chapter. The characteristics of the different containers and iterators are listed; a great help when determining which is most appropriate for a given task.

Yet this is not just a book about the STL: strings, numerics, and the IOStream classes get the same thorough treatment before the book concludes with two topics that are less widely known: internationalization (locales and facets) and allocators. These final two chapters do not disappoint, as the high standards of clarity and accuracy present in the rest of the book are maintained to the end. Each of the sections, from the STL through strings, numerics, and iostreams, would stand on its own.

Throughout the book, the author’s descriptions of the classes and functions are detailed enough to make their usage apparent without delving too deep and drowning his audience in a deluge of information. The examples are all well thought out and pertinent; they do not obscure the message with extraneous code. Both common and not so common traps and pitfalls are presented, aiding comprehension of classes’ semantics. Key information is presented in summary form, often tabulated, as well as in detail; for example, one table lists STL container methods and their degree of exception safety.

Fifty pages of the total 800 are given over to the index. As befits a reference book, the index is very comprehensive and is helpfully set in larger type than the body of the book, making it easy to scan. The hard cover should give this book a long life, and it has been bound in such a way that it will remain open on your desk.

In Conclusion

Just as the library it describes has evolved into far more than could have been dreamed of at its beginning, so this book grew from the author’s original 1993 plan for a 400-page book in his native German to become, by 1999, a volume twice that size written in English. The quality and fluency of the text is higher than is achieved on average by authors to whom English is their first language, and Josuttis’ comprehensive technical understanding of his subject is readily apparent.

I would not hesitate to recommend this book to any practicing C++ programmer. Its broad coverage, combined with the depth of its descriptions and the clarity of its examples, makes it the first (and usually the last) reference I turn to where the library is concerned.

Ben Forshaw is a software consultant for Berkeley Software Services Ltd., with experience in application development in C and C++ on Windows and Unix. He can be reached at b.forshaw@bssl.co.uk.