Nested Requirements

Get an overview of the nested requirements with C++ concepts.

We can use nested requirements to specify additional constraints in a concept without introducing another named concept.

We can think of nested requirements as lambda functions for C++ standard library algorithms. We can use lambdas to alter the behavior of an algorithm without the need to name a function or a function object.

In this case, we can write a constraint more suited to our requirements without naming one more constraint that we would only use in one (nested) context.

Let’s check its syntax below:

requires constraint-expression;

Example 1

Let’s start with a simple example. Here, the concept Coupe uses two other concepts Car and Convertible.

Get hands-on with 1400+ tech skills courses.