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 templates and template aliases
- Learning more ways to specify constraints
- Using concepts to constrain auto parameters
- Exploring the standard concepts library
By the end of this chapter...