Using requires expressions and clauses
In the previous recipe, we introduced the topic of concepts and constraints, learning about them with the help of several examples that were solely based on already existing type traits. Moreover, we also used the terser syntax to specify concepts, with the concept name used instead of the typename
or the class
keyword in the template declaration. However, it is possible to define more complex concepts with the help of requires expressions. These are prvalues of the type bool
that describe the constraints on some template arguments.
In this recipe, we will learn how to write requires expressions and an alternative way to specify constraints on template arguments.
Getting ready
The class template NumericalValue<T>
and the function template wrap()
defined in the previous recipe will be used in the code snippets presented in this recipe.
How to do it...
To specify requirements for template arguments, you can use requires...