C++ Templates: The Complete Guide
832 pages
English
PDF
4.5

C++ Templates: The Complete Guide

C++ Templates: The Complete Guide

Author:

Year:

Summary:

Introduction

The book «C++ Templates: The Complete Guide» is a fundamental work written by three recognized experts in the field of C++: David Vandevoorde, Nicolai Josuttis, and Douglas Gregor. The second edition, published in 2017, has been completely revised to cover the C++11, C++14, and C++17 standards. This is not just a textbook, but a comprehensive reference that covers all aspects of working with templates — from basic concepts to the most complex metaprogramming techniques.

What the book is about

The book is dedicated to the template mechanism in C++ — one of the most powerful and at the same time complex features of the language. The authors systematically cover:

  • Basics: parameterized types, function templates, specialization.
  • Advanced topics: variadic templates, fold expressions, alias templates.
  • Metaprogramming: compile-time computations, constexpr, if constexpr.
  • Type traits and SFINAE: conditional inclusion/exclusion of overloads.
  • Practical techniques: smart pointers, policies, traits, factories.
  • Standard library: std::tuple, std::variant, std::optional and their internal implementation.

Who it is for

The book is intended for experienced C++ developers who already write code confidently but want to understand templates more deeply and learn to use them to create flexible, efficient, and safe libraries. Beginners will find it challenging: knowledge of C++ syntax, memory management, OOP, and basic templates is assumed. However, with persistence, the book can be an excellent springboard for advancing to an expert level.

What the reader will learn

  • How to properly design template classes and functions.
  • How to use variadic templates to handle an arbitrary number of arguments.
  • How to apply SFINAE and std::enable_if for conditional compilation.
  • How to write efficient metaprograms that execute at compile time.
  • How to work with type traits and create custom traits.
  • How standard library containers and smart pointers are implemented internally.
  • How to avoid common mistakes when working with templates (instantiation issues, two-phase name lookup).

Strengths

1. Depth and relevance. The book covers all innovations of C++11/14/17, including auto, decltype, constexpr, if constexpr, fold expressions. This makes it indispensable for modern C++.

2. Structure and clarity. The material is divided into logical parts: basics, implementation details, metaprogramming, practical applications. Each chapter contains numerous code examples, explanations, and warnings.

3. Author authority. Vandevoorde is one of the developers of the C++ standard, Josuttis is the author of the iconic book «C++ Standard Library», Gregor is an expert on templates and Boost. The quality of explanations and precision of wording are of the highest level.

4. Practical value. The book not only explains theory but also shows how to apply templates in real projects: from creating generic algorithms to building libraries.

Who should read it

The book is a must-read for anyone who:

  • Writes C++ professionally and wants to raise their level to expert.
  • Develops libraries or frameworks requiring flexibility and performance.
  • Is preparing for a Senior C++ Developer interview.
  • Is interested in metaprogramming and wants to understand how modern C++ libraries (Boost, Eigen, Range-v3) work.

If you are just starting to learn C++, first read «C++ Primer» or «Programming: Principles

Recommendations