tmp/tmpf13g9tl9/{from.md → to.md}
RENAMED
|
@@ -1,7 +1,9 @@
|
|
| 1 |
### Requires expressions <a id="expr.prim.req">[[expr.prim.req]]</a>
|
| 2 |
|
|
|
|
|
|
|
| 3 |
A *requires-expression* provides a concise way to express requirements
|
| 4 |
on template arguments that can be checked by name lookup
|
| 5 |
[[basic.lookup]] or by checking properties of types and expressions.
|
| 6 |
|
| 7 |
``` bnf
|
|
@@ -9,22 +11,22 @@ requires-expression:
|
|
| 9 |
requires requirement-parameter-listₒₚₜ requirement-body
|
| 10 |
```
|
| 11 |
|
| 12 |
``` bnf
|
| 13 |
requirement-parameter-list:
|
| 14 |
-
'(' parameter-declaration-clause
|
| 15 |
```
|
| 16 |
|
| 17 |
``` bnf
|
| 18 |
requirement-body:
|
| 19 |
'{' requirement-seq '}'
|
| 20 |
```
|
| 21 |
|
| 22 |
``` bnf
|
| 23 |
requirement-seq:
|
| 24 |
requirement
|
| 25 |
-
requirement
|
| 26 |
```
|
| 27 |
|
| 28 |
``` bnf
|
| 29 |
requirement:
|
| 30 |
simple-requirement
|
|
@@ -33,11 +35,11 @@ requirement:
|
|
| 33 |
nested-requirement
|
| 34 |
```
|
| 35 |
|
| 36 |
A *requires-expression* is a prvalue of type `bool` whose value is
|
| 37 |
described below. Expressions appearing within a *requirement-body* are
|
| 38 |
-
unevaluated operands [[
|
| 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:
|
|
@@ -65,13 +67,11 @@ introduces the *requires-expression*.
|
|
| 65 |
|
| 66 |
— *end example*]
|
| 67 |
|
| 68 |
A *requires-expression* may introduce local parameters using a
|
| 69 |
*parameter-declaration-clause* [[dcl.fct]]. A local parameter of a
|
| 70 |
-
*requires-expression* shall not have a default argument.
|
| 71 |
-
introduced by a local parameter is in scope from the point of its
|
| 72 |
-
declaration until the closing brace of the *requirement-body*. These
|
| 73 |
parameters have no linkage, storage, or lifetime; they are only used as
|
| 74 |
notation for the purpose of defining *requirement*s. The
|
| 75 |
*parameter-declaration-clause* of a *requirement-parameter-list* shall
|
| 76 |
not terminate with an ellipsis.
|
| 77 |
|
|
@@ -84,14 +84,10 @@ concept C = requires(T t, ...) { // error: terminates with an ellipsis
|
|
| 84 |
};
|
| 85 |
```
|
| 86 |
|
| 87 |
— *end example*]
|
| 88 |
|
| 89 |
-
The *requirement-body* contains a sequence of *requirement*s. These
|
| 90 |
-
*requirement*s may refer to local parameters, template parameters, and
|
| 91 |
-
any other declarations visible from the enclosing context.
|
| 92 |
-
|
| 93 |
The substitution of template arguments into a *requires-expression* may
|
| 94 |
result in the formation of invalid types or expressions in its
|
| 95 |
*requirement*s or the violation of the semantic constraints of those
|
| 96 |
*requirement*s. In such cases, the *requires-expression* evaluates to
|
| 97 |
`false`; it does not cause the program to be ill-formed. The
|
|
@@ -130,11 +126,12 @@ simple-requirement:
|
|
| 130 |
|
| 131 |
A *simple-requirement* asserts the validity of an *expression*.
|
| 132 |
|
| 133 |
[*Note 1*: The enclosing *requires-expression* will evaluate to `false`
|
| 134 |
if substitution of template arguments into the *expression* fails. The
|
| 135 |
-
*expression* is an unevaluated operand
|
|
|
|
| 136 |
|
| 137 |
[*Example 1*:
|
| 138 |
|
| 139 |
``` cpp
|
| 140 |
template<typename T> concept C =
|
|
@@ -169,19 +166,20 @@ if substitution of template arguments fails. — *end note*]
|
|
| 169 |
template<typename T, typename T::type = 0> struct S;
|
| 170 |
template<typename T> using Ref = T&;
|
| 171 |
|
| 172 |
template<typename T> concept C = requires {
|
| 173 |
typename T::inner; // required nested member name
|
| 174 |
-
typename S<T>; // required
|
|
|
|
| 175 |
typename Ref<T>; // required alias template substitution, fails if T is void
|
| 176 |
};
|
| 177 |
```
|
| 178 |
|
| 179 |
— *end example*]
|
| 180 |
|
| 181 |
A *type-requirement* that names a class template specialization does not
|
| 182 |
-
require that type to be complete [[
|
| 183 |
|
| 184 |
#### Compound requirements <a id="expr.prim.req.compound">[[expr.prim.req.compound]]</a>
|
| 185 |
|
| 186 |
``` bnf
|
| 187 |
compound-requirement:
|
|
@@ -204,10 +202,11 @@ properties proceed in the following order:
|
|
| 204 |
- If the *return-type-requirement* is present, then:
|
| 205 |
- Substitution of template arguments (if any) into the
|
| 206 |
*return-type-requirement* is performed.
|
| 207 |
- The immediately-declared constraint [[temp.param]] of the
|
| 208 |
*type-constraint* for `decltype((E))` shall be satisfied.
|
|
|
|
| 209 |
\[*Example 1*:
|
| 210 |
Given concepts `C` and `D`,
|
| 211 |
``` cpp
|
| 212 |
requires {
|
| 213 |
{ E1 } -> C;
|
|
@@ -286,19 +285,5 @@ template<typename T> concept D = requires (T t) {
|
|
| 286 |
`D<T>` is satisfied if `sizeof(decltype (+t)) == 1`
|
| 287 |
[[temp.constr.atomic]].
|
| 288 |
|
| 289 |
— *end example*]
|
| 290 |
|
| 291 |
-
A local parameter shall only appear as an unevaluated operand
|
| 292 |
-
[[expr.prop]] within the *constraint-expression*.
|
| 293 |
-
|
| 294 |
-
[*Example 2*:
|
| 295 |
-
|
| 296 |
-
``` cpp
|
| 297 |
-
template<typename T> concept C = requires (T a) {
|
| 298 |
-
requires sizeof(a) == 4; // OK
|
| 299 |
-
requires a == 0; // error: evaluation of a constraint variable
|
| 300 |
-
};
|
| 301 |
-
```
|
| 302 |
-
|
| 303 |
-
— *end example*]
|
| 304 |
-
|
|
|
|
| 1 |
### Requires expressions <a id="expr.prim.req">[[expr.prim.req]]</a>
|
| 2 |
|
| 3 |
+
#### General <a id="expr.prim.req.general">[[expr.prim.req.general]]</a>
|
| 4 |
+
|
| 5 |
A *requires-expression* provides a concise way to express requirements
|
| 6 |
on template arguments that can be checked by name lookup
|
| 7 |
[[basic.lookup]] or by checking properties of types and expressions.
|
| 8 |
|
| 9 |
``` bnf
|
|
|
|
| 11 |
requires requirement-parameter-listₒₚₜ requirement-body
|
| 12 |
```
|
| 13 |
|
| 14 |
``` bnf
|
| 15 |
requirement-parameter-list:
|
| 16 |
+
'(' parameter-declaration-clause ')'
|
| 17 |
```
|
| 18 |
|
| 19 |
``` bnf
|
| 20 |
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
|
|
|
|
| 35 |
nested-requirement
|
| 36 |
```
|
| 37 |
|
| 38 |
A *requires-expression* is a prvalue of type `bool` whose value is
|
| 39 |
described below. Expressions appearing within a *requirement-body* are
|
| 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:
|
|
|
|
| 67 |
|
| 68 |
— *end example*]
|
| 69 |
|
| 70 |
A *requires-expression* may introduce local parameters using a
|
| 71 |
*parameter-declaration-clause* [[dcl.fct]]. A local parameter of a
|
| 72 |
+
*requires-expression* shall not have a default argument. These
|
|
|
|
|
|
|
| 73 |
parameters have no linkage, storage, or lifetime; they are only used as
|
| 74 |
notation for the purpose of defining *requirement*s. The
|
| 75 |
*parameter-declaration-clause* of a *requirement-parameter-list* shall
|
| 76 |
not terminate with an ellipsis.
|
| 77 |
|
|
|
|
| 84 |
};
|
| 85 |
```
|
| 86 |
|
| 87 |
— *end example*]
|
| 88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
The substitution of template arguments into a *requires-expression* may
|
| 90 |
result in the formation of invalid types or expressions in its
|
| 91 |
*requirement*s or the violation of the semantic constraints of those
|
| 92 |
*requirement*s. In such cases, the *requires-expression* evaluates to
|
| 93 |
`false`; it does not cause the program to be ill-formed. The
|
|
|
|
| 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* fails. The
|
| 131 |
+
*expression* is an unevaluated operand
|
| 132 |
+
[[term.unevaluated.operand]]. — *end note*]
|
| 133 |
|
| 134 |
[*Example 1*:
|
| 135 |
|
| 136 |
``` cpp
|
| 137 |
template<typename T> concept C =
|
|
|
|
| 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>; // required valid[temp.names] template-id;
|
| 172 |
+
// fails if T::type does not exist as a type to which 0 can be implicitly converted
|
| 173 |
typename Ref<T>; // required alias template substitution, fails if T is void
|
| 174 |
};
|
| 175 |
```
|
| 176 |
|
| 177 |
— *end example*]
|
| 178 |
|
| 179 |
A *type-requirement* that names a class template specialization does not
|
| 180 |
+
require that type to be complete [[term.incomplete.type]].
|
| 181 |
|
| 182 |
#### Compound requirements <a id="expr.prim.req.compound">[[expr.prim.req.compound]]</a>
|
| 183 |
|
| 184 |
``` bnf
|
| 185 |
compound-requirement:
|
|
|
|
| 202 |
- If the *return-type-requirement* is present, then:
|
| 203 |
- Substitution of template arguments (if any) into the
|
| 204 |
*return-type-requirement* is performed.
|
| 205 |
- The immediately-declared constraint [[temp.param]] of the
|
| 206 |
*type-constraint* for `decltype((E))` shall be satisfied.
|
| 207 |
+
|
| 208 |
\[*Example 1*:
|
| 209 |
Given concepts `C` and `D`,
|
| 210 |
``` cpp
|
| 211 |
requires {
|
| 212 |
{ E1 } -> C;
|
|
|
|
| 285 |
`D<T>` is satisfied if `sizeof(decltype (+t)) == 1`
|
| 286 |
[[temp.constr.atomic]].
|
| 287 |
|
| 288 |
— *end example*]
|
| 289 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|