|
964 | 964 | all \grammarterm{template-argument}{s}
|
965 | 965 | in the \grammarterm{simple-template-id}
|
966 | 966 | are non-dependent~(\ref{temp.dep.temp}),
|
967 |
| -the associated constraints |
| 967 | +the associated constraints~(\ref{temp.constr.decl}) |
968 | 968 | of the constrained template
|
969 |
| -shall be satisfied~(\ref{temp.constr.decl}). |
| 969 | +shall be satisfied~(\ref{temp.constr.constr}). |
970 | 970 | \begin{example}
|
971 | 971 | \begin{codeblock}
|
972 | 972 | template<typename T> concept C1 = sizeof(T) != sizeof(int);
|
|
1534 | 1534 |
|
1535 | 1535 | \pnum
|
1536 | 1536 | In order for a constrained template to be instantiated~(\ref{temp.spec}),
|
1537 |
| -its associated constraints shall be \defn{satisfied}~(\ref{temp.constr.decl}). |
| 1537 | +its associated constraints~(\ref{temp.constr.decl}) |
| 1538 | +shall be satisfied as described in the following subsections. |
1538 | 1539 | \begin{note}
|
1539 | 1540 | Forming the name of a specialization of
|
1540 | 1541 | a class template,
|
|
1545 | 1546 | requires the satisfaction of constraints
|
1546 | 1547 | on functions and function templates.
|
1547 | 1548 | \end{note}
|
1548 |
| -The rules for determining the satisfaction of different kinds of |
1549 |
| -constraints are defined in the following subsections. |
1550 | 1549 |
|
1551 | 1550 | \rSec3[temp.constr.op]{Logical operations}
|
1552 | 1551 |
|
|
1566 | 1565 | \pnum
|
1567 | 1566 | A \defn{conjunction} is a constraint taking two
|
1568 | 1567 | operands.
|
1569 |
| -To determine if a conjunction is satisfied, the satisfaction of |
| 1568 | +To determine if a conjunction is |
| 1569 | +\defnx{satisfied}{constraint!satisfaction!conjunction}, |
| 1570 | +the satisfaction of |
1570 | 1571 | the first operand is checked.
|
1571 | 1572 | If that is not satisfied, the conjunction is not satisfied.
|
1572 | 1573 | Otherwise, the conjunction is satisfied if and only if the second
|
|
1576 | 1577 | A \defn{disjunction} is a constraint taking two
|
1577 | 1578 | operands.
|
1578 | 1579 | %
|
1579 |
| -To determine if a disjunction is satisfied, the satisfaction of |
| 1580 | +To determine if a disjunction is |
| 1581 | +\defnx{satisfied}{constraint!satisfaction!disjunction}, |
| 1582 | +the satisfaction of |
1580 | 1583 | the first operand is checked.
|
1581 | 1584 | If that is satisfied, the disjunction is satisfied.
|
1582 | 1585 | Otherwise, the disjunction is satisfied if and only if the second
|
|
1627 | 1630 | according to the rules for expressions described in \ref{temp.over.link}.
|
1628 | 1631 |
|
1629 | 1632 | \pnum
|
1630 |
| -Determining if a constraint is satisfied entails the substitution |
1631 |
| -of the parameter mapping and template arguments into that constraint. |
| 1633 | +To determine if an atomic constraint is |
| 1634 | +\defnx{satisfied}{constraint!satisfaction!atomic}, |
| 1635 | +the parameter mapping and template arguments are |
| 1636 | +first substituted into its expression. |
1632 | 1637 | If substitution results in an invalid type or expression,
|
1633 | 1638 | the constraint is not satisfied.
|
1634 | 1639 | Otherwise, the lvalue-to-rvalue conversion~(\ref{conv.lval})
|
|
1638 | 1643 | results in \tcode{true}.
|
1639 | 1644 | \begin{example}
|
1640 | 1645 | \begin{codeblock}
|
1641 |
| -template<typename T> |
1642 |
| - concept C = sizeof(T) == 4 && !true; // requires atomic constraints |
1643 |
| - // \tcode{sizeof(T) == 4} and \tcode{!true} |
| 1646 | +template<typename T> concept C = |
| 1647 | + sizeof(T) == 4 && !true; // requires atomic constraints |
| 1648 | + // \tcode{sizeof(T) == 4} and \tcode{!true} |
1644 | 1649 |
|
1645 |
| -template<typename T> |
1646 |
| - struct S { |
1647 |
| - constexpr operator bool() const { return true; } |
1648 |
| - }; |
| 1650 | +template<typename T> struct S { |
| 1651 | + constexpr operator bool() const { return true; } |
| 1652 | +}; |
1649 | 1653 |
|
1650 |
| -template<typename T> |
1651 |
| - requires (S<T>{}) |
1652 |
| - void f(T); // \#1 |
1653 |
| -void f(int); // \#2 |
| 1654 | +template<typename T> requires (S<T>{}) |
| 1655 | +void f(T); // \#1 |
| 1656 | +void f(int); // \#2 |
1654 | 1657 |
|
1655 | 1658 | void g() {
|
1656 |
| - f(0); // error: expression \tcode{S<int>\{\}} does not have type \tcode{bool} |
1657 |
| - // while checking satisfaction of deduced arguments of \#1, |
1658 |
| - // even though \#2 is a better match |
1659 |
| -} |
| 1659 | + f(0); // error: expression \tcode{S<int>\{\}} does not have type \tcode{bool} |
| 1660 | +} // while checking satisfaction of deduced arguments of \#1; |
| 1661 | + // call is ill-formed even though \#2 is a better match |
1660 | 1662 | \end{codeblock}
|
1661 | 1663 | \end{example}
|
1662 | 1664 |
|
|
1799 | 1801 | Normalization of \tcode{B}{'s} \grammarterm{constraint-expression}
|
1800 | 1802 | is valid and results in
|
1801 | 1803 | \tcode{T::value} (with the mapping \tcode{T}$\mapsto$\tcode{U*})
|
1802 |
| -$\land$ |
| 1804 | +$\lor$ |
1803 | 1805 | \tcode{true} (with an empty mapping),
|
1804 | 1806 | despite the expression \tcode{T::value} being ill-formed
|
1805 | 1807 | for a pointer type \tcode{T}.
|
|
1828 | 1830 | template<C4 U> void f3(U); // \#3
|
1829 | 1831 | \end{codeblock}
|
1830 | 1832 | The associated constraints of \#1 are
|
1831 |
| -$\tcode{sizeof(T) == 1}$ (with mapping \tcode{T}$\mapsto$\tcode{U}) $\land \tcode{1 == 2}$, |
1832 |
| -those of \#2 are |
1833 |
| -$\tcode{requires \{ typename T::type; \}}$ (with mapping \tcode{T}$\mapsto$\tcode{U}), |
1834 |
| -those of \#3 are |
| 1833 | +$\tcode{sizeof(T) == 1}$ (with mapping \tcode{T}$\mapsto$\tcode{U}) $\land \tcode{1 == 2}$.\\ |
| 1834 | +The associated constraints of \#2 are |
| 1835 | +$\tcode{requires \{ typename T::type; \}}$ (with mapping \tcode{T}$\mapsto$\tcode{U}).\\ |
| 1836 | +The associated constraints of \#3 are |
1835 | 1837 | $\tcode{requires (T x) \{ ++x; \}}$ (with mapping \tcode{T}$\mapsto$\tcode{U}).
|
1836 | 1838 | \end{example}
|
1837 | 1839 | \indextext{constraint!normalization|)}
|
|
2354 | 2356 | a \grammarterm{template-head} equivalent to that
|
2355 | 2357 | of the class template followed by
|
2356 | 2358 | a \grammarterm{template-head} equivalent to that
|
2357 |
| -of the member template. |
| 2359 | +of the member template~(\ref{temp.over.link}). |
2358 | 2360 | \begin{example}
|
2359 | 2361 | \begin{codeblock}
|
2360 | 2362 | template<class T> struct string {
|
|
3561 | 3563 | involving template parameters.
|
3562 | 3564 | Two \grammarterm{template-head}{s} are
|
3563 | 3565 | \defnx{functionally equivalent}{functionally equivalent!\idxgram{template-head}{s}}
|
3564 |
| -if they accept and are satisfied by the same set of template argument |
3565 |
| -lists. |
| 3566 | +if they accept and are satisfied by~(\ref{temp.constr.constr}) |
| 3567 | +the same set of template argument lists. |
3566 | 3568 |
|
3567 | 3569 | \pnum
|
3568 | 3570 | \indextext{template!function!equivalent|see{equivalent, function template}}%
|
|
3867 | 3869 |
|
3868 | 3870 | \pnum
|
3869 | 3871 | A \grammarterm{concept-definition}
|
3870 |
| -declares its \grammarterm{identifier} |
3871 |
| -to be a concept. |
3872 |
| -The name of the concept is a \grammarterm{concept-name}. |
| 3872 | +declares a concept. |
| 3873 | +Its \grammarterm{identifier} becomes a \grammarterm{concept-name} |
| 3874 | +referring to that concept |
| 3875 | +within its scope. |
3873 | 3876 | \begin{example}
|
3874 | 3877 | \begin{codeblock}
|
3875 | 3878 | template<typename T>
|
|
6057 | 6060 | the translation unit containing the explicit instantiation,
|
6058 | 6061 | provided that the associated constraints, if any,
|
6059 | 6062 | of that member are satisfied by the template arguments of the explicit
|
6060 |
| -instantiation~(\ref{temp.constr.decl}), |
| 6063 | +instantiation~(\ref{temp.constr.decl}, \ref{temp.constr.constr}), |
6061 | 6064 | except as described below.
|
6062 | 6065 | \begin{note} In addition, it will typically be an explicit instantiation of certain
|
6063 | 6066 | implementation-dependent data about the class. \end{note}
|
|
6962 | 6965 | or default argument values. If the substitution results in an
|
6963 | 6966 | invalid type, as described above, type deduction fails.
|
6964 | 6967 | If the function template has associated constraints~(\ref{temp.constr.decl}),
|
6965 |
| -those constraints are checked for satisfaction~(\ref{temp.constr}). |
| 6968 | +those constraints are checked for satisfaction~(\ref{temp.constr.constr}). |
6966 | 6969 | If the constraints are not satisfied, type deduction fails.
|
6967 | 6970 |
|
6968 | 6971 | \pnum
|
|
0 commit comments