Advertisement
Membership
Login
ACCU Buttons
Search in Book Reviews
Search is a simple string search in either book title or book author. The full text search is a search of the text of the review.
This book succeeds phenomenally at filling the hole.
You can rest assured that the authors know what they're talking about. Nicolai Josuttis should already be well known to you as the author ofThe C++ Standard Library, another must-have book. David Vandevoorde may be less familiar. He is an engineer at EDG, which produces a C++ compiler front end widely acknowledged to be the most standards-conforming available. He was also the main implementor of EDG's support for exported templates, the only implementation of this (controversial) feature on the market. InC++ Templates, Josuttis and Vandevoorde live up to their excellent reputations by presenting accurate and useful information in a clear, easy-to-read manner.
Let me list some of the high points so you can see why this book is so useful. Part I of IV is titled The Basics. It begins with a brisk tutorial/review of function templates in Chapter 2, and class templates in Chapter 3. This material is probably familiar, but reading these chapters will clear up any lingering confusion you may have. Already after Chapter 3 we enter territory where many C++ programmers will struggle. The remaining chapters in Part I are Nontype Template Parameters (Chapter 4), Tricky Basics (Chapter 5), which among other things discusses using the keywords typename and template for dependent names, Using Templates in Practice (Chapter 6), which covers compilation models and debugging techniques, and Basic Template Terminology (Chapter 7).
Part II isTemplates in Depth.All but the most battle-hardened template coder will learn something here. With topics such as name lookup, SFINAE, points of instantiation, argument deduction ... this part alone is worth the price of the entire book. Part III,Templates in Designand Part IV,Advanced Applicationsboth discuss more concrete details of applying templates to real problems. These also contain a wealth of sample code.
While the information in this book will vastly improve the quality of your template code, another equally valuable contribution is specifying the vocabulary with which we talk about templates. Clarifying the conventional meaning of terms such as traits, policies, template arguments, template parameters, etc. will aid in more precise communication between programmers. As an example, I have already seen the term SFINAE, which the authors have coined, popping up in newsgroups and mailing lists. SFINAE stands for Substitution Failure Is Not An Error, and is a principle that enables remarkable compile-time techniques such as checking for the existence of a particular method in a class.
Now, to keep this review from being entirely one-sided, here are my three complaints. During my review, I was able to contribute several typos to the online errata; however, these are all minor annoyances that shouldn't cause real confusion. Second, I felt that Chapter 13 on Future Directions, which discusses possible additions and changes to templates in C++0x would have been better left as an appendix. Although quite interesting and worth reading, this chapter is necessarily more speculative and may become dated relatively soon. Finally, my biggest complaint is that the
SArray(simple array) template class presented at the beginning of chapter 18 on expression templates holds some dangers for naïve readers. The copy constructor is not exception-safe; it will leak memory if the contained type's assignment operator throws. Second, the use of assert statements for error checking is inconsistent (assigning two differently-sized arrays will trigger an assertion, but adding them together may silently read past the end of the smaller one). Although these issues are not strictly relevant in the context of expression templates, I felt that this class failed to meet the high standard established by the rest of the book.
But don't let these few complaints dissuade you. Overall this is an excellent book. If you only buy one new C++ book this year, this should be it.