tmp/tmpkbgjv_5w/{from.md → to.md}
RENAMED
|
@@ -21,12 +21,11 @@ requirement-body:
|
|
| 21 |
'{' requirement-seq '}'
|
| 22 |
```
|
| 23 |
|
| 24 |
``` bnf
|
| 25 |
requirement-seq:
|
| 26 |
-
requirement
|
| 27 |
-
requirement requirement-seq
|
| 28 |
```
|
| 29 |
|
| 30 |
``` bnf
|
| 31 |
requirement:
|
| 32 |
simple-requirement
|
|
@@ -34,12 +33,11 @@ requirement:
|
|
| 34 |
compound-requirement
|
| 35 |
nested-requirement
|
| 36 |
```
|
| 37 |
|
| 38 |
A *requires-expression* is a prvalue of type `bool` whose value is
|
| 39 |
-
described below.
|
| 40 |
-
unevaluated operands [[term.unevaluated.operand]].
|
| 41 |
|
| 42 |
[*Example 1*:
|
| 43 |
|
| 44 |
A common use of *requires-expression*s is to define requirements in
|
| 45 |
concepts such as the one below:
|
|
@@ -66,38 +64,43 @@ The first `requires` introduces the *requires-clause*, and the second
|
|
| 66 |
introduces the *requires-expression*.
|
| 67 |
|
| 68 |
— *end example*]
|
| 69 |
|
| 70 |
A *requires-expression* may introduce local parameters using a
|
| 71 |
-
*parameter-declaration-clause*
|
| 72 |
-
*requires-expression* shall not have a default argument.
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
| 77 |
|
| 78 |
[*Example 2*:
|
| 79 |
|
| 80 |
``` cpp
|
| 81 |
template<typename T>
|
| 82 |
concept C = requires(T t, ...) { // error: terminates with an ellipsis
|
| 83 |
t;
|
| 84 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
```
|
| 86 |
|
| 87 |
— *end example*]
|
| 88 |
|
| 89 |
-
The substitution of template arguments into a *requires-expression*
|
| 90 |
-
result in the formation of invalid types or expressions in
|
| 91 |
-
*requirement*s or the violation
|
| 92 |
-
*requirement*s. In such cases, the
|
| 93 |
-
`false`; it does not cause the
|
| 94 |
-
|
| 95 |
-
and stops when a condition that
|
| 96 |
-
*requires-expression* is encountered. If
|
| 97 |
-
semantic constraint checking succeed, the
|
| 98 |
-
evaluates to `true`.
|
| 99 |
|
| 100 |
[*Note 1*: If a *requires-expression* contains invalid types or
|
| 101 |
expressions in its *requirement*s, and it does not appear within the
|
| 102 |
declaration of a templated entity, then the program is
|
| 103 |
ill-formed. — *end note*]
|
|
@@ -109,11 +112,11 @@ diagnostic required.
|
|
| 109 |
[*Example 3*:
|
| 110 |
|
| 111 |
``` cpp
|
| 112 |
template<typename T> concept C =
|
| 113 |
requires {
|
| 114 |
-
new
|
| 115 |
};
|
| 116 |
```
|
| 117 |
|
| 118 |
— *end example*]
|
| 119 |
|
|
@@ -122,16 +125,16 @@ requires {
|
|
| 122 |
``` bnf
|
| 123 |
simple-requirement:
|
| 124 |
expression ';'
|
| 125 |
```
|
| 126 |
|
| 127 |
-
A *simple-requirement* asserts the validity of an *expression*.
|
|
|
|
| 128 |
|
| 129 |
[*Note 1*: The enclosing *requires-expression* will evaluate to `false`
|
| 130 |
-
if substitution of template arguments into the *expression*
|
| 131 |
-
|
| 132 |
-
[[term.unevaluated.operand]]. — *end note*]
|
| 133 |
|
| 134 |
[*Example 1*:
|
| 135 |
|
| 136 |
``` cpp
|
| 137 |
template<typename T> concept C =
|
|
@@ -151,13 +154,17 @@ as a *simple-requirement*.
|
|
| 151 |
#### Type requirements <a id="expr.prim.req.type">[[expr.prim.req.type]]</a>
|
| 152 |
|
| 153 |
``` bnf
|
| 154 |
type-requirement:
|
| 155 |
typename nested-name-specifierₒₚₜ type-name ';'
|
|
|
|
|
|
|
| 156 |
```
|
| 157 |
|
| 158 |
-
A *type-requirement* asserts the validity of a type.
|
|
|
|
|
|
|
| 159 |
|
| 160 |
[*Note 1*: The enclosing *requires-expression* will evaluate to `false`
|
| 161 |
if substitution of template arguments fails. — *end note*]
|
| 162 |
|
| 163 |
[*Example 1*:
|
|
@@ -166,13 +173,15 @@ if substitution of template arguments fails. — *end note*]
|
|
| 166 |
template<typename T, typename T::type = 0> struct S;
|
| 167 |
template<typename T> using Ref = T&;
|
| 168 |
|
| 169 |
template<typename T> concept C = requires {
|
| 170 |
typename T::inner; // required nested member name
|
| 171 |
-
typename S<T>;
|
| 172 |
-
|
| 173 |
typename Ref<T>; // required alias template substitution, fails if T is void
|
|
|
|
|
|
|
| 174 |
};
|
| 175 |
```
|
| 176 |
|
| 177 |
— *end example*]
|
| 178 |
|
|
@@ -189,13 +198,14 @@ compound-requirement:
|
|
| 189 |
``` bnf
|
| 190 |
return-type-requirement:
|
| 191 |
'->' type-constraint
|
| 192 |
```
|
| 193 |
|
| 194 |
-
A *compound-requirement* asserts properties of the *expression* E.
|
| 195 |
-
|
| 196 |
-
|
|
|
|
| 197 |
|
| 198 |
- Substitution of template arguments (if any) into the *expression* is
|
| 199 |
performed.
|
| 200 |
- If the `noexcept` specifier is present, E shall not be a
|
| 201 |
potentially-throwing expression [[except.spec]].
|
|
|
|
| 21 |
'{' requirement-seq '}'
|
| 22 |
```
|
| 23 |
|
| 24 |
``` bnf
|
| 25 |
requirement-seq:
|
| 26 |
+
requirement requirement-seqₒₚₜ
|
|
|
|
| 27 |
```
|
| 28 |
|
| 29 |
``` bnf
|
| 30 |
requirement:
|
| 31 |
simple-requirement
|
|
|
|
| 33 |
compound-requirement
|
| 34 |
nested-requirement
|
| 35 |
```
|
| 36 |
|
| 37 |
A *requires-expression* is a prvalue of type `bool` whose value is
|
| 38 |
+
described below.
|
|
|
|
| 39 |
|
| 40 |
[*Example 1*:
|
| 41 |
|
| 42 |
A common use of *requires-expression*s is to define requirements in
|
| 43 |
concepts such as the one below:
|
|
|
|
| 64 |
introduces the *requires-expression*.
|
| 65 |
|
| 66 |
— *end example*]
|
| 67 |
|
| 68 |
A *requires-expression* may introduce local parameters using a
|
| 69 |
+
*parameter-declaration-clause*. A local parameter of a
|
| 70 |
+
*requires-expression* shall not have a default argument. The type of
|
| 71 |
+
such a parameter is determined as specified for a function parameter in
|
| 72 |
+
[[dcl.fct]]. These parameters have no linkage, storage, or lifetime;
|
| 73 |
+
they are only used as notation for the purpose of defining
|
| 74 |
+
*requirement*s. The *parameter-declaration-clause* of a
|
| 75 |
+
*requirement-parameter-list* shall not terminate with an ellipsis.
|
| 76 |
|
| 77 |
[*Example 2*:
|
| 78 |
|
| 79 |
``` cpp
|
| 80 |
template<typename T>
|
| 81 |
concept C = requires(T t, ...) { // error: terminates with an ellipsis
|
| 82 |
t;
|
| 83 |
};
|
| 84 |
+
template<typename T>
|
| 85 |
+
concept C2 = requires(T p[2]) {
|
| 86 |
+
(decltype(p))nullptr; // OK, p has type ``pointer to T''
|
| 87 |
+
};
|
| 88 |
```
|
| 89 |
|
| 90 |
— *end example*]
|
| 91 |
|
| 92 |
+
The substitution of template arguments into a *requires-expression* can
|
| 93 |
+
result in the formation of invalid types or expressions in the immediate
|
| 94 |
+
context of its *requirement*s [[temp.deduct.general]] or the violation
|
| 95 |
+
of the semantic constraints of those *requirement*s. In such cases, the
|
| 96 |
+
*requires-expression* evaluates to `false`; it does not cause the
|
| 97 |
+
program to be ill-formed. The substitution and semantic constraint
|
| 98 |
+
checking proceeds in lexical order and stops when a condition that
|
| 99 |
+
determines the result of the *requires-expression* is encountered. If
|
| 100 |
+
substitution (if any) and semantic constraint checking succeed, the
|
| 101 |
+
*requires-expression* evaluates to `true`.
|
| 102 |
|
| 103 |
[*Note 1*: If a *requires-expression* contains invalid types or
|
| 104 |
expressions in its *requirement*s, and it does not appear within the
|
| 105 |
declaration of a templated entity, then the program is
|
| 106 |
ill-formed. — *end note*]
|
|
|
|
| 112 |
[*Example 3*:
|
| 113 |
|
| 114 |
``` cpp
|
| 115 |
template<typename T> concept C =
|
| 116 |
requires {
|
| 117 |
+
new decltype((void)T{}); // ill-formed, no diagnostic required
|
| 118 |
};
|
| 119 |
```
|
| 120 |
|
| 121 |
— *end example*]
|
| 122 |
|
|
|
|
| 125 |
``` bnf
|
| 126 |
simple-requirement:
|
| 127 |
expression ';'
|
| 128 |
```
|
| 129 |
|
| 130 |
+
A *simple-requirement* asserts the validity of an *expression*. The
|
| 131 |
+
*expression* is an unevaluated operand.
|
| 132 |
|
| 133 |
[*Note 1*: The enclosing *requires-expression* will evaluate to `false`
|
| 134 |
+
if substitution of template arguments into the *expression*
|
| 135 |
+
fails. — *end note*]
|
|
|
|
| 136 |
|
| 137 |
[*Example 1*:
|
| 138 |
|
| 139 |
``` cpp
|
| 140 |
template<typename T> concept C =
|
|
|
|
| 154 |
#### Type requirements <a id="expr.prim.req.type">[[expr.prim.req.type]]</a>
|
| 155 |
|
| 156 |
``` bnf
|
| 157 |
type-requirement:
|
| 158 |
typename nested-name-specifierₒₚₜ type-name ';'
|
| 159 |
+
typename splice-specifier
|
| 160 |
+
typename splice-specialization-specifier
|
| 161 |
```
|
| 162 |
|
| 163 |
+
A *type-requirement* asserts the validity of a type. The component names
|
| 164 |
+
of a *type-requirement* are those of its *nested-name-specifier* (if
|
| 165 |
+
any) and *type-name* (if any).
|
| 166 |
|
| 167 |
[*Note 1*: The enclosing *requires-expression* will evaluate to `false`
|
| 168 |
if substitution of template arguments fails. — *end note*]
|
| 169 |
|
| 170 |
[*Example 1*:
|
|
|
|
| 173 |
template<typename T, typename T::type = 0> struct S;
|
| 174 |
template<typename T> using Ref = T&;
|
| 175 |
|
| 176 |
template<typename T> concept C = requires {
|
| 177 |
typename T::inner; // required nested member name
|
| 178 |
+
typename S<T>; // required valid[temp.names] template-id; fails if T::type does not exist as a type
|
| 179 |
+
// to which 0 can be implicitly converted
|
| 180 |
typename Ref<T>; // required alias template substitution, fails if T is void
|
| 181 |
+
typename [:T::r1:]; // fails if T::r1 is not a reflection of a type
|
| 182 |
+
typename [:T::r2:]<int>; // fails if T::r2 is not a reflection of a template Z for which Z<int> is a type
|
| 183 |
};
|
| 184 |
```
|
| 185 |
|
| 186 |
— *end example*]
|
| 187 |
|
|
|
|
| 198 |
``` bnf
|
| 199 |
return-type-requirement:
|
| 200 |
'->' type-constraint
|
| 201 |
```
|
| 202 |
|
| 203 |
+
A *compound-requirement* asserts properties of the *expression* E. The
|
| 204 |
+
*expression* is an unevaluated operand. Substitution of template
|
| 205 |
+
arguments (if any) and verification of semantic properties proceed in
|
| 206 |
+
the following order:
|
| 207 |
|
| 208 |
- Substitution of template arguments (if any) into the *expression* is
|
| 209 |
performed.
|
| 210 |
- If the `noexcept` specifier is present, E shall not be a
|
| 211 |
potentially-throwing expression [[except.spec]].
|