
We earn a commission if you buy through these links. Learn more
Modern C++ Design
A classic, dense guide to policy-based design and compile-time generic programming in C++, showing how to build flexible components without runtime cost.
What It's About
Modern C++ Design is a book about using C++ templates to build libraries that are flexible without being slow. Alexandrescu's central move is to split a class's behavior into independent policies, such as how an object is created, how it is stored, or how errors are handled, and then combine those policies through templates at compile time. The examples come from the Loki library he wrote, so they are real designs rather than toy snippets.
The style is dense and deliberate. Each chapter typically starts from a familiar design pattern, such as a singleton, factory, or visitor, asks what actually varies in it, and then rebuilds the pattern as a generic component. He leans on typelists, a compile-time list type he develops from scratch, and some code runs for pages before the payoff. Reading it feels less like following a tutorial and more like watching an experienced engineer reason through a problem out loud.
Be aware of when it was written. The book targets C++98 and the template tools of that era, so many techniques are wrapped in verbose syntax that later language features have simplified. The ideas still hold up, but you will read the code with a modern eye and may want to translate it as you go. Expect to work through it slowly, with a compiler open.
Read this if you…
- want to understand how template-heavy libraries like Loki are put together
- already comfortable with templates and want to push them further
- design reusable C++ components and care about compile-time flexibility
Skip it if you…
- want a practical, up-to-date guide to modern C++ idioms
- are new to C++ templates and want a gentle introduction
Key Ideas
- 1
Policy-based class design
The core technique is to separate a class into a host and several interchangeable policy parameters, each handling one concern such as allocation, ownership, or threading. Because the policies are template arguments, the compiler assembles a specialized class for each combination, so you get customization without virtual calls or a tangle of inheritance. This is the idea most readers come away using.
- 2
Typelists as compile-time data
Alexandrescu builds a list of types using templates alone, then writes algorithms that operate on it, such as searching, indexing, and generating combinations. This turns the compiler into a computation engine for type-level logic. It is the foundation for much of the later machinery, and it shows how far template metaprogramming can be pushed.
- 3
Generic versions of classic design patterns
Patterns such as singleton, factory, visitor, and command are reconsidered as reusable components rather than code you retype for each project. The book asks which parts of a pattern are fixed and which can be parameterized, then encodes the variable parts as policies. The result is a set of library-quality designs you can study and adapt.
- 4
Smart pointers as tunable components
Ownership and checking behavior are treated as a family of policies, so a smart pointer can be configured for different storage, copying, and error-handling strategies. The discussion shows how small design choices change the semantics a user sees. It is a useful model for thinking about any resource-managing type you write.
Limitations
The book is tied to C++98 and its template limitations. Variadic templates, constexpr, the type traits in the standard library, and standard smart pointers now cover much of the same ground, so some code looks clumsy by today's standards. Compile error messages from these techniques can be hard to decode, and the dense examples can feel punishing. It also does not cover concurrency, modern build practices, or the wider C++ ecosystem. Some critics argue the designs are more impressive than practical for everyday application code.
Questions Readers Ask
- Do I need to know C++ templates before reading it?
- Yes. You should be comfortable with function and class templates, specialization, and basic metaprogramming. The book does not teach these basics from scratch; it builds quickly on them. If templates still feel shaky, work through a dedicated reference such as C++ Templates: The Complete Guide first.
- Is Modern C++ Design still worth reading today?
- Yes, mainly for the ideas rather than the syntax. Policy-based design and compile-time composition remain useful, and the thinking carries over to current C++. For up-to-date techniques, pair it with Effective Modern C++ by Scott Meyers, which covers C++11 and C++14 features.
- Published
- 2001
- ISBN
- 9780201704310
- Difficulty
- advanced
- Category
- Tech
Book details and cover from Google Books.
Ready to read Modern C++ Design?
Get your copy on Amazon, or listen to it on Audible. We earn a commission if you buy through these links.