Files
2025-10-25 03:02:53 +03:00

7.2 KiB

[temp.constr.order]

13 Templates [temp]

13.5 Template constraints [temp.constr]

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

1

#

A constraint P subsumes a constraint Q if and only if, for every disjunctive clause Pi in the disjunctive normal form110 of P, Pi subsumes every conjunctive clause Qj in the conjunctive normal form111 of Q, where

a disjunctive clause Pi subsumes a conjunctive clause Qj if and only if there exists an atomic constraint Pia in Pi for which there exists an atomic constraint Qjb in Qj such that Pia subsumes Qjb,

an atomic constraint A subsumes another atomic constraintB if and only if A and B are identical using the rules described in [temp.constr.atomic], and

a fold expanded constraint A subsumes another fold expanded constraint B if they are compatible for subsumption, have the same fold-operator, and the constraint of A subsumes that of B.

[Example 1:

Let A and B be atomic constraints.

The constraint A ∧ B subsumes A, but A does not subsume A ∧ B.

The constraint A subsumes A ∨ B, but A ∨ B does not subsume A.

Also note that every constraint subsumes itself.

— end example]

2

#

[Note 1:

The subsumption relation defines a partial ordering on constraints.

This partial ordering is used to determine

the best viable candidate of non-template functions ([over.match.best]),

the address of a non-template function ([over.over]),

the matching of template template arguments ([temp.arg.template]),

the partial ordering of class template specializations ([temp.spec.partial.order]), and

the partial ordering of function templates ([temp.func.order]).

— end note]

3

#

The associated constraints C of a declaration Dare eligible for subsumption unless C contains a concept-dependent constraint.

4

#

A declaration D1 isat least as constrained as a declaration D2 if

D1 and D2 are both constrained declarations andD1's associated constraints are eligible for subsumption and subsume those of D2; or

D2 has no associated constraints.

5

#

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 2: template concept C1 = requires(T t) { --t; };template concept C2 = C1 && requires(T t) { *t; };

template void f(T); // #1template void f(T); // #2template void g(T); // #3template void g(T); // #4 f(0); // selects #1 f((int*)0); // selects #2 g(true); // selects #3 because C1 is not satisfied g(0); // selects #4 — end example]

[Example 3: template<template concept CT, typename T>struct S {};templateconcept A = true;

template<template concept X, typename T>int f(S<X, T>) requires A { return 42; } // #1template<template concept X, typename T>int f(S<X, T>) requires X { return 43; } // #2 f(S<A, int>{}); // ok, select #1 because #2 is not eligible for subsumption — end example]

6

#

A non-template function F1 is more partial-ordering-constrained than a non-template function F2 if

they have the same non-object-parameter-type-lists ([dcl.fct]), and

if they are member functions, both are direct members of the same class, and

if both are non-static member functions, they have the same types for their object parameters, and

the declaration of F1 is more constrained than the declaration of F2.

110)110)

A constraint is in disjunctive normal form when it is a disjunction of clauses where each clause is a conjunction of fold expanded or atomic constraints.

For atomic constraints A, B, and C, the disjunctive normal form of the constraintA ∧ (B ∨ C) is(A ∧ B) ∨ (A ∧ C).

Its disjunctive clauses are (A ∧ B) and (A ∧ C).

111)111)

A constraint is in conjunctive normal form when it is a conjunction of clauses where each clause is a disjunction of fold expanded or atomic constraints.

For atomic constraints A, B, and C, the constraintA ∧ (B ∨ C) is in conjunctive normal form.

Its conjunctive clauses are A and (B ∨ C).