What This Course Covers

Get to know the topics we are going to explore in this course.

Course structure

We’ve structured this course into three distinct parts: core template concepts, advanced template features, and applied templates. In this lesson, we’ll provide a brief overview of the topics covered within each of these parts.

Press + to interact

Core template concepts

In this part, we’ll begin with an introduction to templates and understand their benefits. We’ll then learn about the syntax for writing function templates, class templates, variable templates, and alias templates. We’ll explore concepts such as template instantiation and template specialization and learn how to write templates with a variable number of arguments.

This part comprises the following sections:

The “Template Basics” section provides an introduction to the concept of template metaprogramming in C++, with several simple examples, and a discussion on why we need templates and the pros and cons of using templates.

The “Template Fundamentals” section explores all forms of templates in C++: function templates, class templates, variable templates, and alias templates. For each of these, we discuss the syntax and the details of how they work. Furthermore, the key concepts of template instantiation and specialization are addressed here.

The “Variadic Templates” section is dedicated entirely to variadic templates, which are templates that have a variable number of template parameters. We discuss in detail variadic function templates, variadic class templates, variadic alias templates, variadic variable templates, parameter packs and how they are expanded, and fold expressions that help us simplify the writing of variadic templates.

Advanced template features

In this part, we’ll explore a variety of advanced features, including name binding and dependent names, template recursion, template argument deduction, and forwarding references. Here, we’ll learn about type traits that help us query information about types and perform conditional compilation using various language features. Furthermore, we’ll learn how to specify requirements on template arguments with C++20 concepts and constraints and explore the content of the standard concepts library.

This part comprises the following sections:

The “Advanced Template Concepts” section groups a series of advanced template concepts, such as dependent names and name lookup, template argument deduction, template recursion, perfect forwarding, and generic and template lambdas. By understanding these topics, readers will be able to greatly expand the variety of templates they can read or write.

The “Type Traits and Conditional Compilation” section is dedicated to type traits. We’ll learn about type traits, what traits the standard library provides, and how they can be used to solve different problems.

The “Concepts and Constraints” section presents the new C++20 mechanism for defining requirements for template arguments with concepts and constraints. We’ll learn about the various ways to specify constraints. Moreover, we provide an overview of the content of the C++20 standard concepts library.

Applied template

In this part, we’ll put to practice the knowledge of templates we have accumulated so far. We’ll learn about static polymorphism and patterns, such as the Curiously Recurring Template Pattern (CRTP) and mixins, as well as type erasure, tag dispatching, expression templates, and typelists. We will also learn about the design of standard containers, iterators, and algorithms, and we’ll learn to implement our own. We’ll explore the C++20 Ranges library with its ranges and constrained algorithms, and we’ll learn how to write our own range adaptor.

This part comprises the following sections:

The “Patterns and Idioms” section explores a series of unrelated advanced topics of using the knowledge learned so far to implement various patterns. We explore the concepts of static polymorphism, type erasure, tag dispatching, and patterns, such as the curiously recursive template pattern, expression templates, mixins, and typelists.

The “Ranges and Algorithms” section is dedicated to understanding containers, iterators, and algorithms, which are the core components of the standard template library. We’ll learn here how to write a generic container and an iterator type for it as well as a general-purpose algorithm.

The “The Ranges Library” section explores the new C++20 Ranges library with its key features, such as ranges, range adaptors, and constrained algorithms. These enable us to write simpler code for working with ranges. Furthermore, the we’ll also learn here how to write our own range adaptor.

We also provide quizzes at the end of each section, which contain questions and answers for all the concepts we discussed in that section.