Chapter 6, Concepts and Constraints
Question 1
What are constraints? What about concepts?
Answer
A constraint is a requirement imposed on a template argument. A concept is a named set of one or more constraints.
Question 2
What is a requires clause and a requires expression?
Answer
A requires clause is a construct that allows us to specify a constraint on a template argument or function declaration. This construct is composed of the requires
keyword followed by a compile-time Boolean expression. A requires clause affects the behavior of a function, including it for overload resolution only if the Boolean expression is true
. On the other hand, a requires expression has the requires (parameters-list) expression;
form, where parameters-list
is optional. Its purpose is to verify that some expressions are well-formed, without having any side effects or affecting the behavior of the function. Requires expressions can be used with requires clauses, although named concepts...