Requires Expressions
Get introduced to the 'requires' keyword and its functionalities.
We'll cover the following
Thanks to requires
expressions, you can define powerful concepts. A requires
expression has the following form:
requires (parameter-list(optional)) {requirement-seq}
parameter-list
: A comma-separated list of parameters, such as in a function declarationrequirement-seq
: A sequence of requirements, consisting of simple, type, compound, or nested requirements
Let’s discuss its type one by one.
Simple requirements
The following concept Addable
is a simple requirement:
template <typename T>
concept Addable = requires (T a, T b) {
a + b;
};
The concept Addable
requires that the addition a + b
of two values of the same type T
is possible.
Get hands-on with 1400+ tech skills courses.