From Jason Turner

[stmt.ranged]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpjje_n_65/{from.md → to.md} +31 -47
tmp/tmpjje_n_65/{from.md → to.md} RENAMED
@@ -1,65 +1,49 @@
1
  ### The range-based `for` statement <a id="stmt.ranged">[[stmt.ranged]]</a>
2
 
3
- For a range-based `for` statement of the form
4
 
5
  ``` bnf
6
- 'for (' for-range-declaration : expression ')' statement
7
  ```
8
 
9
- let *range-init* be equivalent to the *expression* surrounded by
10
- parentheses[^2]
11
-
12
- ``` bnf
13
- '(' expression ')'
14
- ```
15
-
16
- and for a range-based `for` statement of the form
17
-
18
- ``` bnf
19
- 'for' '(' for-range-declaration ':' braced-init-list ')' statement
20
- ```
21
-
22
- let *range-init* be equivalent to the *braced-init-list*. In each case,
23
- a range-based `for` statement is equivalent to
24
-
25
- ``` cpp
26
- {
27
- auto && __range = range-init;
28
- for ( auto __begin = begin-expr,
29
- __end = end-expr;
30
- __begin != __end;
31
- ++__begin ) {
32
- for-range-declaration = *__begin;
33
- statement
34
- }
35
- }
36
- ```
37
-
38
- where `__range`, `__begin`, and `__end` are variables defined for
39
- exposition only, and `_RangeT` is the type of the *expression*, and
40
- *begin-expr* and *end-expr* are determined as follows:
41
-
42
- - if `_RangeT` is an array type, *begin-expr* and *end-expr* are
43
- `__range` and `__range + __bound`, respectively, where `__bound` is
44
- the array bound. If `_RangeT` is an array of unknown size or an array
45
- of incomplete type, the program is ill-formed;
46
- - if `_RangeT` is a class type, the *unqualified-id*s `begin` and `end`
47
- are looked up in the scope of class `\mbox{_RangeT}` as if by class
48
- member access lookup ([[basic.lookup.classref]]), and if either (or
49
- both) finds at least one declaration, *begin-expr* and *end-expr* are
50
- `__range.begin()` and `__range.end()`, respectively;
51
  - otherwise, *begin-expr* and *end-expr* are `begin(__range)` and
52
- `end(__range)`, respectively, where `begin` and `end` are looked up in
53
- the associated namespaces ([[basic.lookup.argdep]]). Ordinary
54
- unqualified lookup ([[basic.lookup.unqual]]) is not performed.
 
 
 
55
 
56
  ``` cpp
57
  int array[5] = { 1, 2, 3, 4, 5 };
58
  for (int& x : array)
59
  x *= 2;
60
  ```
61
 
 
 
62
  In the *decl-specifier-seq* of a *for-range-declaration*, each
63
  *decl-specifier* shall be either a *type-specifier* or `constexpr`. The
64
  *decl-specifier-seq* shall not define a class or enumeration.
65
 
 
1
  ### The range-based `for` statement <a id="stmt.ranged">[[stmt.ranged]]</a>
2
 
3
+ The range-based `for` statement
4
 
5
  ``` bnf
6
+ 'for (' for-range-declaration ':' for-range-initializer ')' statement
7
  ```
8
 
9
+ is equivalent to
10
+
11
+ where
12
+
13
+ - if the *for-range-initializer* is an *expression*, it is regarded as
14
+ if it were surrounded by parentheses (so that a comma operator cannot
15
+ be reinterpreted as delimiting two *init-declarator*s);
16
+ - `__range`, `__begin`, and `__end` are variables defined for exposition
17
+ only; and
18
+ - *begin-expr* and *end-expr* are determined as follows:
19
+ - if the *for-range-initializer* is an expression of array type `R`,
20
+ *begin-expr* and *end-expr* are `__range` and `__range + __bound`,
21
+ respectively, where `__bound` is the array bound. If `R` is an array
22
+ of unknown bound or an array of incomplete type, the program is
23
+ ill-formed;
24
+ - if the *for-range-initializer* is an expression of class type `C`,
25
+ the *unqualified-id*s `begin` and `end` are looked up in the scope
26
+ of `C` as if by class member access lookup (
27
+ [[basic.lookup.classref]]), and if either (or both) finds at least
28
+ one declaration, *begin-expr* and *end-expr* are `__range.begin()`
29
+ and `__range.end()`, respectively;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  - otherwise, *begin-expr* and *end-expr* are `begin(__range)` and
31
+ `end(__range)`, respectively, where `begin` and `end` are looked up
32
+ in the associated namespaces ([[basic.lookup.argdep]]).
33
+ \[*Note 1*: Ordinary unqualified lookup ([[basic.lookup.unqual]])
34
+ is not performed. — *end note*]
35
+
36
+ [*Example 1*:
37
 
38
  ``` cpp
39
  int array[5] = { 1, 2, 3, 4, 5 };
40
  for (int& x : array)
41
  x *= 2;
42
  ```
43
 
44
+ — *end example*]
45
+
46
  In the *decl-specifier-seq* of a *for-range-declaration*, each
47
  *decl-specifier* shall be either a *type-specifier* or `constexpr`. The
48
  *decl-specifier-seq* shall not define a class or enumeration.
49