Module 05 of 10

Templates & Generic Programming

Lessons

About This Module

A template is a pattern that lets the compiler write code for you. Instead of repeating the same function or class for int, float and std::string, you write it once with a type parameter and the compiler generates each version when it is used. This module starts with the basics of function templates and class templates.

It then covers template specialization, which lets you provide a custom version of a template for one particular type, and finishes with concepts, the C++20 feature that states what a type must support before it can be used with a template, giving clearer errors and safer generic code.

Watch the lessons in order, then continue on to STL: Containers & Algorithms.

Lessons

4 videos
01

Templates in C++

How a template lets the compiler generate functions and classes from a pattern, with practical examples and when templates are worth using.

02

Function Templates & Class Templates

A hands-on webinar on writing function templates and class templates, and how the compiler instantiates them for each type you use.

03

Class Template Specialization

How to specialize a class template for a specific type, including partial specialization, with worked examples.

04

Concept-Based Generic Programming

Bjarne Stroustrup shows how C++ concepts express constraints on generic code and make templates safer and easier to use.