Composing Constraints

Take your knowledge of constraints to the next level by performing conjunctions and disjunctions on constraints.

We have seen multiple examples of constraining template arguments, but in all the cases so far, we used a single constraint. It’s possible, though, for constraints to be composed using the && and || operators. A composition of two constraints using the && operator is called a conjunction and the composition of two constraints using the || operator is called a disjunction.

Constraint conjunctions

For a conjunction to be true, both constraints must be true. Like in the case of logical AND operations, the two constraints are evaluated from left to right, and if the left constraint is false, the right constraint is not evaluated. Let’s look at an example:

Get hands-on with 1200+ tech skills courses.