Chapter 6: Concepts and Constraints

The C++20 standard provides a series of significant improvements to template metaprogramming with concepts and constraints. A constraint is a modern way to define requirements on template parameters. A concept is a set of named constraints. Concepts provide several benefits to the traditional way of writing templates, mainly improved readability of code, better diagnostics, and reduced compilation times.

In this chapter, we will address the following topics:

  • Understanding the need for concepts
  • Defining concepts
  • Exploring requires expressions
  • Composing constraints
  • Learning about the ordering of templates with constraints
  • Constraining non-template member functions
  • Constraining class templates
  • Constraining variable ...

Get Template Metaprogramming with C++ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.