A bird's-eye view of template C++

Slide header

Masterclass on templates and template metaprogramming in C++.

Abstract

C++ is a multi-paradigm programming language. This means it lends itself to solve a specific problem in various forms or styles. One of those forms or styles is object-oriented programming, with which C++ is often identified. Another strong suit of C++ is the support for generic programming and template metaprogramming. In this session we are going to look at modern-day C++ templates, and how we can use them effectively. Template programming sometimes has the reputation of being hard to understand and adopt, which surely may be the case for highly advanced usage. However, we will see that templates can be used for a myriad of purposes, which often have a low barrier to entry. Command of templates will greatly improve your efficiency and productivity as a C++ programmer. The topics we are going to cover include: generic programming, metaprogramming, type traits, static/compile-time polymorphism, variadic templates, and much more. Not only will we look at the state of templates in C++17, we will also address what C++20 and the future has to offer. Join me in this session exploring the wonderful and interesting world of C++ templates, and improve or refresh your knowledge.

Audience

This session is for professionals in software engineering, level novice to advanced, interested in C++. However, the underlying ideas of generic programming, metaprogramming and type traits do apply to many other languages. Are you a beginner or novice in C++? This session will introduce you to many topics related to template programming, as well as showing in-depth subtleties. The extensive list of resources accompanying the session will point you in the right direction to go about exploring yourself. Are you an advanced, experienced C++ engineer? Join me in this session to refresh your knowledge and perhaps discover new details or perspectives on the matter. There’s something here for everyone!

Topic listing

These are the main topics addressed in the talk:

  1. Introduction
  • The C++ ecosystem
  • History of C++ and templates
  • What are templates?
  • Compile-time programming
  • Generic programming
  • Class templates
  • Function templates
  • Variable templates
  • Alias templates
  • Concepts
  • Template parameters
  • Variadic templates
  1. Templates in practice
  • Type and function templates
  • Template specialization
  1. Taming templates
  • Polymorphism in C++
  • Compile-time polymorphism
  • Constraining templated entities
  • Static assertions
  • Type traits
  • C++20 Concepts
  1. Template metaprogramming
  • SFINAE

Conferences

A slimmed-down version of this session was presented at the C++ Italy Conference 2021, see here for the recording.