13 Templates [temp]

13.5 Template constraints [temp.constr]

13.5.4 Partial ordering by constraints [temp.constr.order]

A constraint P subsumes a constraint Q if and only if, for every disjunctive clause in the disjunctive normal form130 of P, subsumes every conjunctive clause in the conjunctive normal form131 of Q, where
  • a disjunctive clause subsumes a conjunctive clause if and only if there exists an atomic constraint in for which there exists an atomic constraint in such that subsumes , and
  • an atomic constraint A subsumes another atomic constraint B if and only if A and B are identical using the rules described in [temp.constr.atomic].
Example
:
Let A and B be atomic constraints.
The constraint subsumes A, but A does not subsume .
The constraint A subsumes , but does not subsume A.
Also note that every constraint subsumes itself.
— end example
 ]
Note
:
The subsumption relation defines a partial ordering on constraints.
This partial ordering is used to determine
— end note
 ]
A declaration D1 is at least as constrained as a declaration D2 if
  • D1 and D2 are both constrained declarations and D1's associated constraints subsume those of D2; or
  • D2 has no associated constraints.
A declaration D1 is more constrained than another declaration D2 when D1 is at least as constrained as D2, and D2 is not at least as constrained as D1.
Example
:
template<typename T> concept C1 = requires(T t) { --t; };
template<typename T> concept C2 = C1<T> && requires(T t) { *t; };

template<C1 T> void f(T);       // #1
template<C2 T> void f(T);       // #2
template<typename T> void g(T); // #3
template<C1 T> void g(T);       // #4

f(0);                           // selects #1
f((int*)0);                     // selects #2
g(true);                        // selects #3 because C1<bool> is not satisfied
g(0);                           // selects #4
— end example
 ]
A constraint is in disjunctive normal form when it is a disjunction of clauses where each clause is a conjunction of atomic constraints.
Example
:
For atomic constraints A, B, and C, the disjunctive normal form of the constraint is .
Its disjunctive clauses are and .
— end example
 ]
A constraint is in conjunctive normal form when it is a conjunction of clauses where each clause is a disjunction of atomic constraints.
Example
:
For atomic constraints A, B, and C, the constraint is in conjunctive normal form.
Its conjunctive clauses are A and .
— end example
 ]