tmp/tmp3pfc_2k4/{from.md → to.md}
RENAMED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#### General <a id="expr.prim.req.general">[[expr.prim.req.general]]</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
|
| 8 |
+
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 requirement-seq
|
| 26 |
+
```
|
| 27 |
+
|
| 28 |
+
``` bnf
|
| 29 |
+
requirement:
|
| 30 |
+
simple-requirement
|
| 31 |
+
type-requirement
|
| 32 |
+
compound-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 [[term.unevaluated.operand]].
|
| 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:
|
| 44 |
+
|
| 45 |
+
``` cpp
|
| 46 |
+
template<typename T>
|
| 47 |
+
concept R = requires (T i) {
|
| 48 |
+
typename T::type;
|
| 49 |
+
{*i} -> std::convertible_to<const typename T::type&>;
|
| 50 |
+
};
|
| 51 |
+
```
|
| 52 |
+
|
| 53 |
+
A *requires-expression* can also be used in a *requires-clause*
|
| 54 |
+
[[temp.pre]] as a way of writing ad hoc constraints on template
|
| 55 |
+
arguments such as the one below:
|
| 56 |
+
|
| 57 |
+
``` cpp
|
| 58 |
+
template<typename T>
|
| 59 |
+
requires requires (T x) { x + x; }
|
| 60 |
+
T add(T a, T b) { return a + b; }
|
| 61 |
+
```
|
| 62 |
+
|
| 63 |
+
The first `requires` introduces the *requires-clause*, and the second
|
| 64 |
+
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. These
|
| 71 |
+
parameters have no linkage, storage, or lifetime; they are only used as
|
| 72 |
+
notation for the purpose of defining *requirement*s. The
|
| 73 |
+
*parameter-declaration-clause* of a *requirement-parameter-list* shall
|
| 74 |
+
not terminate with an ellipsis.
|
| 75 |
+
|
| 76 |
+
[*Example 2*:
|
| 77 |
+
|
| 78 |
+
``` cpp
|
| 79 |
+
template<typename T>
|
| 80 |
+
concept C = requires(T t, ...) { // error: terminates with an ellipsis
|
| 81 |
+
t;
|
| 82 |
+
};
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
— *end example*]
|
| 86 |
+
|
| 87 |
+
The substitution of template arguments into a *requires-expression* may
|
| 88 |
+
result in the formation of invalid types or expressions in its
|
| 89 |
+
*requirement*s or the violation of the semantic constraints of those
|
| 90 |
+
*requirement*s. In such cases, the *requires-expression* evaluates to
|
| 91 |
+
`false`; it does not cause the program to be ill-formed. The
|
| 92 |
+
substitution and semantic constraint checking proceeds in lexical order
|
| 93 |
+
and stops when a condition that determines the result of the
|
| 94 |
+
*requires-expression* is encountered. If substitution (if any) and
|
| 95 |
+
semantic constraint checking succeed, the *requires-expression*
|
| 96 |
+
evaluates to `true`.
|
| 97 |
+
|
| 98 |
+
[*Note 1*: If a *requires-expression* contains invalid types or
|
| 99 |
+
expressions in its *requirement*s, and it does not appear within the
|
| 100 |
+
declaration of a templated entity, then the program is
|
| 101 |
+
ill-formed. — *end note*]
|
| 102 |
+
|
| 103 |
+
If the substitution of template arguments into a *requirement* would
|
| 104 |
+
always result in a substitution failure, the program is ill-formed; no
|
| 105 |
+
diagnostic required.
|
| 106 |
+
|
| 107 |
+
[*Example 3*:
|
| 108 |
+
|
| 109 |
+
``` cpp
|
| 110 |
+
template<typename T> concept C =
|
| 111 |
+
requires {
|
| 112 |
+
new int[-(int)sizeof(T)]; // ill-formed, no diagnostic required
|
| 113 |
+
};
|
| 114 |
+
```
|
| 115 |
+
|
| 116 |
+
— *end example*]
|
| 117 |
+
|