From Jason Turner

[temp.constr.constr]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp1jztu_tv/{from.md → to.md} +90 -4
tmp/tmp1jztu_tv/{from.md → to.md} RENAMED
@@ -2,16 +2,18 @@
2
 
3
  #### General <a id="temp.constr.constr.general">[[temp.constr.constr.general]]</a>
4
 
5
  A *constraint* is a sequence of logical operations and operands that
6
  specifies requirements on template arguments. The operands of a logical
7
- operation are constraints. There are three different kinds of
8
  constraints:
9
 
10
  - conjunctions [[temp.constr.op]],
11
- - disjunctions [[temp.constr.op]], and
12
- - atomic constraints [[temp.constr.atomic]].
 
 
13
 
14
  In order for a constrained template to be instantiated [[temp.spec]],
15
  its associated constraints [[temp.constr.decl]] shall be satisfied as
16
  described in the following subclauses.
17
 
@@ -190,11 +192,12 @@ void h2() {
190
 
191
  — *end note*]
192
 
193
  To determine if an atomic constraint is *satisfied*, the parameter
194
  mapping and template arguments are first substituted into its
195
- expression. If substitution results in an invalid type or expression,
 
196
  the constraint is not satisfied. Otherwise, the lvalue-to-rvalue
197
  conversion [[conv.lval]] is performed if necessary, and `E` shall be a
198
  constant expression of type `bool`. The constraint is satisfied if and
199
  only if evaluation of `E` results in `true`. If, at different points in
200
  the program, the satisfaction result is different for identical atomic
@@ -221,5 +224,88 @@ void g() {
221
  // call is ill-formed even though #2 is a better match
222
  ```
223
 
224
  — *end example*]
225
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  #### General <a id="temp.constr.constr.general">[[temp.constr.constr.general]]</a>
4
 
5
  A *constraint* is a sequence of logical operations and operands that
6
  specifies requirements on template arguments. The operands of a logical
7
+ operation are constraints. There are five different kinds of
8
  constraints:
9
 
10
  - conjunctions [[temp.constr.op]],
11
+ - disjunctions [[temp.constr.op]],
12
+ - atomic constraints [[temp.constr.atomic]],
13
+ - concept-dependent constraints [[temp.constr.concept]], and
14
+ - fold expanded constraints [[temp.constr.fold]].
15
 
16
  In order for a constrained template to be instantiated [[temp.spec]],
17
  its associated constraints [[temp.constr.decl]] shall be satisfied as
18
  described in the following subclauses.
19
 
 
192
 
193
  — *end note*]
194
 
195
  To determine if an atomic constraint is *satisfied*, the parameter
196
  mapping and template arguments are first substituted into its
197
+ expression. If substitution results in an invalid type or expression in
198
+ the immediate context of the atomic constraint [[temp.deduct.general]],
199
  the constraint is not satisfied. Otherwise, the lvalue-to-rvalue
200
  conversion [[conv.lval]] is performed if necessary, and `E` shall be a
201
  constant expression of type `bool`. The constraint is satisfied if and
202
  only if evaluation of `E` results in `true`. If, at different points in
203
  the program, the satisfaction result is different for identical atomic
 
224
  // call is ill-formed even though #2 is a better match
225
  ```
226
 
227
  — *end example*]
228
 
229
+ #### Concept-dependent constraints <a id="temp.constr.concept">[[temp.constr.concept]]</a>
230
+
231
+ A *concept-dependent constraint* `CD` is an atomic constraint whose
232
+ expression is a concept-id `CI` whose *concept-name* names a dependent
233
+ concept named `C`.
234
+
235
+ To determine if `CD` is *satisfied*, the parameter mapping and template
236
+ arguments are first substituted into `C`. If substitution results in an
237
+ invalid concept-id in the immediate context of the constraint
238
+ [[temp.deduct.general]], the constraint is not satisfied. Otherwise, let
239
+ `CI'` be the normal form [[temp.constr.normal]] of the concept-id after
240
+ substitution of `C`.
241
+
242
+ [*Note 1*: Normalization of `CI` might be ill-formed; no diagnostic is
243
+ required. — *end note*]
244
+
245
+ To form `CI''`, each appearance of `C`'s template parameters in the
246
+ parameter mappings of the atomic constraints (including
247
+ concept-dependent constraints) in `CI'` is substituted with their
248
+ respective arguments from the parameter mapping of `CD` and the
249
+ arguments of `CI`.
250
+
251
+ `CD` is satisfied if `CI''` is satisfied.
252
+
253
+ [*Note 2*: Checking whether `CI''` is satisfied can lead to further
254
+ normalization of concept-dependent constraints. — *end note*]
255
+
256
+ [*Example 1*:
257
+
258
+ ``` cpp
259
+ template<typename>
260
+ concept C = true;
261
+
262
+ template<typename T, template<typename> concept CC>
263
+ concept D = CC<T>;
264
+
265
+ template<typename U,
266
+ template<typename> concept CT,
267
+ template<typename, template<typename> concept> concept CU>
268
+ int f() requires CU<U, CT>;
269
+ int i = f<int, C, D>();
270
+ ```
271
+
272
+ In this example, the associated constraints of `f` consist of a
273
+ concept-dependent constraint whose expression is the concept-id
274
+ `CU<U, CT>` with the mapping `U` ↦ `U`, `CT` ↦ `CT`, `CU` ↦ `CU`. The
275
+ result of substituting `D` into this expression is `D<U, CT>`. We
276
+ consider the normal form of the resulting concept-id, which is `CC<T>`
277
+ with the mapping `T` ↦ `U`, `CC` ↦ `CT`. By recursion, `C` is
278
+ substituted into `CC<T>`, and the result is normalized to the atomic
279
+ constraint `true`, which is satisfied.
280
+
281
+ — *end example*]
282
+
283
+ #### Fold expanded constraint <a id="temp.constr.fold">[[temp.constr.fold]]</a>
284
+
285
+ A *fold expanded constraint* is formed from a constraint C and a
286
+ *fold-operator* which can either be `&&` or `||`. A fold expanded
287
+ constraint is a pack expansion [[temp.variadic]]. Let N be the number of
288
+ elements in the pack expansion parameters [[temp.variadic]].
289
+
290
+ A fold expanded constraint whose *fold-operator* is `&&` is satisfied if
291
+ it is a valid pack expansion and if N = 0 or if for each i where
292
+ 0 ≤ i < N in increasing order, C is satisfied when replacing each pack
293
+ expansion parameter with the corresponding iᵗʰ element. No substitution
294
+ takes place for any i greater than the smallest i for which the
295
+ constraint is not satisfied.
296
+
297
+ A fold expanded constraint whose *fold-operator* is `||` is satisfied if
298
+ it is a valid pack expansion, N > 0, and if for i where 0 ≤ i < N in
299
+ increasing order, there is a smallest i for which C is satisfied when
300
+ replacing each pack expansion parameter with the corresponding iᵗʰ
301
+ element. No substitution takes place for any i greater than the smallest
302
+ i for which the constraint is satisfied.
303
+
304
+ [*Note 1*: If the pack expansion expands packs of different size, then
305
+ it is invalid and the fold expanded constraint is not
306
+ satisfied. — *end note*]
307
+
308
+ Two fold expanded constraints are *compatible for subsumption* if their
309
+ respective constraints both contain an equivalent unexpanded pack
310
+ [[temp.over.link]].
311
+