C++ Templates: The Complete Guide
David Vandevoorde and Micolai M. Josuttis

bdbs commerce | beta


Softcover: 552 pages
Publisher: Addison-Wesley Professional; Edition 1 (November 22, 2002)
Language: English
ISBN-10: 0201734842
ISBN-13: 978-0201734843
Physical Trim: 9.5 x 7.5 x 1.2 inches

C++ Templates: The Complete Guide
David Vandevoorde and Micolai M. Josuttis

bdbs commerce | beta


C++ Templates: The Complete Guide

Templates are among the most powerful features of C++, but they are too often neglected, misunderstood, and misused. C++ Templates: The Complete Guide provides software architects and engineers with a clear understanding of why, when, and how to use templates to build and maintain cleaner, faster, and smarter software more efficiently.

C++ Templates begins with an insightful tutorial on basic concepts and language features. The remainder of the book serves as a comprehensive reference, focusing first on language details, then on a wide range of coding techniques, and finally on advanced applications for templates. Examples used throughout the book illustrate abstract concepts and demonstrate best practices.

This practical guide shows programmers how to exploit the full power of the template features in C++. The companion Web site at contains sample code and additional updates.


The exact behaviors of templates
How to avoid the pitfalls associated with templates
Idioms and techniques, from the basic to the previously undocumented
How to reuse source code without threatening performance or safety
How to increase the efficiency of C++ programs
How to produce more flexible and maintainable software

About the Authors

David Vandevoorde is an engineer at the Edison Design Group. He is an active member of the ANSI C++ Standards Committee, and a cofounder of the newsgroup comp.lang.c++.moderated. A graduate of the Brussels Free University and the Rensselaer Polytechnic Institute, his interests include algorithm development, programming languages, and teaching. See

Nicolai M. Josuttis is an independent technical consultant who designs object-oriented software for the telecommunications, traffic, finance, and manufacturing industries. He is an active member of the C++ Standards Committee Library Working Group. Nicolai has written several books on object-oriented programming and C++. See

This book is often very technical and not the easiest to read. Nevertheless, the quality of the information it contains is great. All aspects of template programming are covered, from generic programming to template meta programming passing by traits and policy classes.

The first two chapters introduce function templates and class templates. The third chapter is about the nontype template parameters. Indeed, template parameters can be values and not types. For example, you can pass int constants as template parameters. Then, the two following chapters are more about templates in practice. You will learn the different way to include template code in your common C++ base code. You will also see some tricks useful in the development of templates. The last chapter of this first part is fixing a terminology for templates.

The second part of the book (Templates in-Depth) begins with the fundamentals of templates in-depth. Next, the names in templates are covered in details. And after that, we have three very technical and complex chapters. The first covers the instantiations of templates in-depth, the second covers the template argument detection and the next one is about specializations and overloading. The last chapter of this part is about the future directions of the C++ templates. This chapter covers some extensions that have been added to library and compilers, but were not in C++ standard at the time the book was written. Some of these futures directions are now part of the new C++11 standard.

The next part (Templates and Design) is about the techniques that can be used to improve your software design using templates. The first chapter covers the most common use of templates: compile-time polymorphism. Then, the traits and policy classes are covered. The traits classes are a way to add more information to a template parameter and policy classes represent a configurable behavior for templates. The 16th is talking about some optimization that can be made about templates and inheritance. The next chapter focuses on template metaprogramming. A metaprogram is a program that is not computed at runtime, but at compile-time resulting in performance sometimes very important. Then, the last chapter introduces the expression templates. This technique is a way to encapsulate expressions into templates in order to optimize some computations. The example is about matrix computations.

The final part (Advanced Applications) present four examples in which the templates brings a lot of power. The first example is about type classification. How to know at compile-time of what kind is a given type and makes something depending on the characteristics of the type. The second example is about developing Smart Pointers. The next one presents an implementation of tuples with templates and the last one implements function objects and callbacks. These four examples are not made to be used instead of the standard library, but there are good examples to prove the power of templates.

This book is a very good guide on templates. It covers most of the details that you will encounter in the creation and development of templates or in working with templatized libraries such as Boost.