My book “Template Metaprogramming with C++” is now available

Template Metaprogramming with C++

I am pleased to announce that my latest book, Template Metaprogramming with C++ (ISBN 9781803243450), has been published by Packt and can be ordered from both Amazon and Packtpub.

📘 What is this book about?

This book is focused entirely on templates and metaprogramming. You will learn everything from template syntax to variadic templates, from template recursion to argument deduction. You will explore in detail type traits and conditional compilation, constraints and concepts, as well as a variety of patterns such as the Curiously Recuring Template Pattern, mixins, type erasure, type dispatching, and more. You will also learn about containers, iterators, and algorithms, as well as the C++20 ranges library.

👥 Who is this book for?

This book is primarily intended for beginner to intermediate C++ developers that want to learn templates and generic programming. If you are such a developer, you must have basic C++ knowledge, as the book is not teaching the basics of the language (except for the templates part). However, if you are an experienced C++ developer you can still find the book useful, as it covers a variety of C++20 topics such as concepts, the ranges library, and generic lambdas.

📃 What topics does the book cover?

The book has the following structure (most covered topics are mentioned in parenthesis):

  • Chapter 1An Introduction to Templates (basic syntax, terminology, history of templates, pros and cons)
  • Chapter 2Template Fundamentals (syntax for function templates, class templates, variable templates, alias templates, lambda templates, instantiation, specialization, template parameters)
  • Chapter 3Variadic Templates (templates with variable number of arguments, parameter packs, fold expressions)
  • Chapter 4Advanced Template Concepts (name binding and dependent names, template recursion, template argument deduction, forwarding references, decltype, std::declval, friends)
  • Chapter 5Type Traits and Conditional Compilation (type traits, SFINAE, enable_if, constexpr if, standard type traits library)
  • Chapter 6Concepts and Constraints (concepts, requires expressions, composing constraints, constraining templates, abbreviated function templates, standard concepts library)
  • Chapter 7Patterns and Idioms (dynamic versus static polymorphism, Curiously Recurring Template Pattern, mixins, type erasure, tag dispatching, expression templates, typelists)
  • Chapter 8Ranges and Algorithms (containers, iterators, algorithms, writing a custom container, iterator, and generic algorithm)
  • Chapter 9The Ranges Library (range adapters, constrained algorithms, writing a custom range adaptor)

👨‍💻 Where is the source code?

All the code snippets from the book can be found on GitHub in Packt’s Template-Metaprogramming-with-CPP repository.

You can try all the snippets from the book using an online compiler, such as Wandbox and Compiler Explorer.

💬 Feedback

This book is the result of one year of work. I tried to put the things in such a way that they are easy to follow and understand. I can only hope you will find it helpful for learning C++ templates. It is only you that can tell whether I succeeded to create an enjoyable and compelling book. Therefore, your feedback as a review/rating of the book on Amazon or Packtpub (or any other form) is welcomed.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.