Experienced C++ developers who are constantly looking for better techniques, better design, and better solutions will appreciate this book. The author presents new ways of using, and thinking in, C++. Along the way, he shows how to write elegant, efficient, powerful, highly reusable, and highly customizable code in the language.
This book is not intended for beginners in C++. It is not a tutorial on C++, or on object-oriented programming. It is about generic programming in C++ using templates, and about generic implementation of common design patterns. Proficiency in C++ in general, and templates in particular, is a prerequisite for understanding the techniques and code presented in this book.
The presentation of each topic is systematic, and the author makes good use of examples throughout the book. The author starts with the discussion of the problem, presents a basic solution, and refines the solution until it meets all the requirements. He discusses the various design tradeoffs made at each step of the refinement process. This makes it easy to understand the rationale behind his final solution. The author shows great insight in each of the solutions presented in the book.
The book is organized into two parts; the first part describes techniques for building generic components, and the second part shows implementation of generic components. The book is divided into 11 chapters.
In chapter 1, the author discusses policy-based classes, building blocks of highly reusable design elements. Chapter 2 presents various C++ techniques, used by the author in later chapters to build generic components. Chapter 3 presents a new and interesting concept called Typelist, which is a powerful tool for manipulating collection of types at compile-time. In chapter 4, the author discusses the design and implementation of a fast and efficient small-object allocator. Chapter 5 covers generalized functors that are useful in implementing the design patterns like Command. Generalized functors can be used in designs that need requests to be stored in objects. Chapter 6 presents a highly customizable implementation of the Singleton pattern.
Chapter 7 discusses various implementations of smart pointers. Chapter 8 presents the implementation of object factories, an extensible and generic method for creating objects. Chapter 9 discusses generic implementation of the Abstract Factory design pattern. In chapter 10, the author discusses generic implementations of the Visitor design pattern. In chapter 11 the author discusses multi-methods, a mechanism that dispatches a function call to different concrete functions depending on the dynamic type of multiple objects involved in the call.
The techniques presented in book are refreshing and thought-provoking. The solutions presented for each problem discussed in the book are definitely of high quality. However, heavy use of templates sometimes makes the code difficult to read. Some may find the solutions presented in the book too complicated, and may prefer to use simpler solutions. In software engineering, code can be written in many different ways to achieve the same end result. The techniques and implementations presented in this book are definitely worth considering. The author demonstrates techniques to use the compiler as a code generator, techniques that force the compiler to do the heavy lifting.
The book includes a discussion of, and generic implementations of, various design patterns from Design Patterns by Gamma et al. . In addition, it also serves as documentation on Loki, a free library developed by the author. One great thing about Loki is that you do not even have to type in the code presented in the book; the library is available for download, and can be used for free.
As with everything else in life, however, Loki is not without drawbacks. Loki uses advanced features from standard C++, and the techniques and code presented in the book will not work with compilers that do not support the C++ standard completely. Microsoft’s Visual C++ compiler, one of the most widely used C++ compilers for the Windows platform, happens to be one of these. The code has been tested only with two compilers, Metrowerk’s CodeWarrior Pro 6.0, and Comeau C++ 4.2.38, both on the Windows platform.
The other drawback to the book is that it includes quite a few errors that will be easily caught by an expert C++ developer, but that will confuse others. Unfortunately, there is no errata available, either on the author’s website, or on the publisher’s website for the book.
This book will help C++ developers write efficient, highly reusable, and highly customizable code. I highly recommend this book to C++ developers who use compilers that can compile the Loki library source code.