From Jason Turner

[iterator.requirements]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpoj47cqx3/{from.md → to.md} +86 -56
tmp/tmpoj47cqx3/{from.md → to.md} RENAMED
@@ -5,16 +5,16 @@
5
  Iterators are a generalization of pointers that allow a C++program to
6
  work with different data structures (containers) in a uniform manner. To
7
  be able to construct template algorithms that work correctly and
8
  efficiently on different types of data structures, the library
9
  formalizes not just the interfaces but also the semantics and complexity
10
- assumptions of iterators. All input iterators `i` support the expression
11
  `*i`, resulting in a value of some object type `T`, called the *value
12
- type* of the iterator. All output iterators support the expression
13
- `*i = o` where `o` is a value of some type that is in the set of types
14
- that are *writable* to the particular iterator type of `i`. All
15
- iterators `i` for which the expression `(*i).m` is well-defined, support
16
  the expression `i->m` with the same semantics as `(*i).m`. For every
17
  iterator type `X` for which equality is defined, there is a
18
  corresponding signed integer type called the *difference type* of the
19
  iterator.
20
 
@@ -41,33 +41,58 @@ iterators also satisfy all the requirements of forward iterators and can
41
  be used whenever a forward iterator is specified; Random access
42
  iterators also satisfy all the requirements of bidirectional iterators
43
  and can be used whenever a bidirectional iterator is specified.
44
 
45
  Iterators that further satisfy the requirements of output iterators are
46
- called *mutable iterator*s. Nonmutable iterators are referred to as
47
- *constant iterator*s.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
 
49
  Just as a regular pointer to an array guarantees that there is a pointer
50
  value pointing past the last element of the array, so for any iterator
51
  type there is an iterator value that points past the last element of a
52
  corresponding sequence. These values are called *past-the-end* values.
53
  Values of an iterator `i` for which the expression `*i` is defined are
54
  called *dereferenceable*. The library never assumes that past-the-end
55
  values are dereferenceable. Iterators can also have singular values that
56
- are not associated with any sequence. After the declaration of an
57
- uninitialized pointer `x` (as with `int* x;`), `x` must always be
58
- assumed to have a singular value of a pointer. Results of most
59
- expressions are undefined for singular values; the only exceptions are
60
- destroying an iterator that holds a singular value, the assignment of a
61
- non-singular value to an iterator that holds a singular value, and, for
62
- iterators that satisfy the `DefaultConstructible` requirements, using a
63
- value-initialized iterator as the source of a copy or move operation.
64
- This guarantee is not offered for default initialization, although the
65
- distinction only matters for types with trivial default constructors
66
- such as pointers or aggregates holding pointers. In these cases the
67
- singular value is overwritten the same way as any other value.
68
- Dereferenceable values are always non-singular.
 
 
 
 
 
 
 
69
 
70
  An iterator `j` is called *reachable* from an iterator `i` if and only
71
  if there is a finite sequence of applications of the expression `++i`
72
  that makes `i == j`. If `j` is reachable from `i`, they refer to
73
  elements of the same sequence.
@@ -95,23 +120,24 @@ In the following sections, `a` and `b` denote values of type `X` or
95
  `const X`, `difference_type` and `reference` refer to the types
96
  `iterator_traits<X>::difference_type` and
97
  `iterator_traits<X>::reference`, respectively, `n` denotes a value of
98
  `difference_type`, `u`, `tmp`, and `m` denote identifiers, `r` denotes a
99
  value of `X&`, `t` denotes a value of value type `T`, `o` denotes a
100
- value of some type that is writable to the output iterator. For an
101
- iterator type `X` there must be an instantiation of
102
- `iterator_traits<X>` ([[iterator.traits]]).
 
103
 
104
  ### Iterator <a id="iterator.iterators">[[iterator.iterators]]</a>
105
 
106
  The `Iterator` requirements form the basis of the iterator concept
107
  taxonomy; every iterator satisfies the `Iterator` requirements. This set
108
  of requirements specifies operations for dereferencing and incrementing
109
  an iterator. Most algorithms will require additional operations to
110
  read ([[input.iterators]]) or write ([[output.iterators]]) values, or
111
  to provide a richer set of iterator movements ([[forward.iterators]],
112
- [[bidirectional.iterators]], [[random.access.iterators]]).)
113
 
114
  A type `X` satisfies the `Iterator` requirements if:
115
 
116
  - `X` satisfies the `CopyConstructible`, `CopyAssignable`, and
117
  `Destructible` requirements ([[utility.arg.requirements]]) and
@@ -120,85 +146,89 @@ A type `X` satisfies the `Iterator` requirements if:
120
  have the indicated semantics.
121
 
122
  ### Input iterators <a id="input.iterators">[[input.iterators]]</a>
123
 
124
  A class or pointer type `X` satisfies the requirements of an input
125
- iterator for the value type `T` if X satisfies the `Iterator` (
126
  [[iterator.iterators]]) and `EqualityComparable` (Table 
127
- [[equalitycomparable]]) requirements and the expressions in Table 
128
  [[tab:iterator.input.requirements]] are valid and have the indicated
129
  semantics.
130
 
131
  In Table  [[tab:iterator.input.requirements]], the term *the domain of
132
  `==`* is used in the ordinary mathematical sense to denote the set of
133
  values over which `==` is (required to be) defined. This set can change
134
  over time. Each algorithm places additional requirements on the domain
135
  of `==` for the iterator values it uses. These requirements can be
136
- inferred from the uses that algorithm makes of `==` and `!=`. the call
137
- `find(a,b,x)` is defined only if the value of `a` has the property *p*
138
- defined as follows: `b` has property *p* and a value `i` has property
139
- *p* if `(*i==x)` or if `(*i!=x` and `++i` has property `p`).
140
 
141
- For input iterators, `a == b` does not imply `++a == ++b`. (Equality
142
- does not guarantee the substitution property or referential
 
 
 
 
 
143
  transparency.) Algorithms on input iterators should never attempt to
144
  pass through the same iterator twice. They should be *single pass*
145
- algorithms. Value type T is not required to be a `CopyAssignable` type
146
- (Table  [[copyassignable]]). These algorithms can be used with istreams
147
- as the source of the input data through the `istream_iterator` class
148
- template.
149
 
150
  ### Output iterators <a id="output.iterators">[[output.iterators]]</a>
151
 
152
  A class or pointer type `X` satisfies the requirements of an output
153
  iterator if `X` satisfies the `Iterator` requirements (
154
  [[iterator.iterators]]) and the expressions in Table 
155
  [[tab:iterator.output.requirements]] are valid and have the indicated
156
  semantics.
157
 
158
- The only valid use of an `operator*` is on the left side of the
159
- assignment statement. *Assignment through the same value of the iterator
160
- happens only once.* Algorithms on output iterators should never attempt
161
- to pass through the same iterator twice. They should be *single pass*
162
- algorithms. Equality and inequality might not be defined. Algorithms
163
- that take output iterators can be used with ostreams as the destination
164
- for placing data through the `ostream_iterator` class as well as with
165
- insert iterators and insert pointers.
166
 
167
  ### Forward iterators <a id="forward.iterators">[[forward.iterators]]</a>
168
 
169
  A class or pointer type `X` satisfies the requirements of a forward
170
  iterator if
171
 
172
  - `X` satisfies the requirements of an input iterator (
173
  [[input.iterators]]),
174
- - X satisfies the `DefaultConstructible` requirements (
175
  [[utility.arg.requirements]]),
176
  - if `X` is a mutable iterator, `reference` is a reference to `T`; if
177
- `X` is a const iterator, `reference` is a reference to `const T`,
178
  - the expressions in Table  [[tab:iterator.forward.requirements]] are
179
  valid and have the indicated semantics, and
180
  - objects of type `X` offer the multi-pass guarantee, described below.
181
 
182
- The domain of == for forward iterators is that of iterators over the
183
  same underlying sequence. However, value-initialized iterators may be
184
  compared and shall compare equal to other value-initialized iterators of
185
- the same type. value initialized iterators behave as if they refer past
186
- the end of the same empty sequence
 
 
187
 
188
  Two dereferenceable iterators `a` and `b` of type `X` offer the
189
  *multi-pass guarantee* if:
190
 
191
  - `a == b` implies `++a == ++b` and
192
  - `X` is a pointer type or the expression `(void)++X(a), *a` is
193
  equivalent to the expression `*a`.
194
 
195
- The requirement that `a == b` implies `++a == ++b` (which is not true
196
- for input and output iterators) and the removal of the restrictions on
197
- the number of the assignments through a mutable iterator (which applies
198
- to output iterators) allows the use of multi-pass one-directional
199
- algorithms with forward iterators.
200
 
201
  If `a` and `b` are equal, then either `a` and `b` are both
202
  dereferenceable or else neither is dereferenceable.
203
 
204
  If `a` and `b` are both dereferenceable, then `a == b` if and only if
@@ -209,12 +239,12 @@ If `a` and `b` are both dereferenceable, then `a == b` if and only if
209
  A class or pointer type `X` satisfies the requirements of a
210
  bidirectional iterator if, in addition to satisfying the requirements
211
  for forward iterators, the following expressions are valid as shown in
212
  Table  [[tab:iterator.bidirectional.requirements]].
213
 
214
- Bidirectional iterators allow algorithms to move iterators backward as
215
- well as forward.
216
 
217
  ### Random access iterators <a id="random.access.iterators">[[random.access.iterators]]</a>
218
 
219
  A class or pointer type `X` satisfies the requirements of a random
220
  access iterator if, in addition to satisfying the requirements for
 
5
  Iterators are a generalization of pointers that allow a C++program to
6
  work with different data structures (containers) in a uniform manner. To
7
  be able to construct template algorithms that work correctly and
8
  efficiently on different types of data structures, the library
9
  formalizes not just the interfaces but also the semantics and complexity
10
+ assumptions of iterators. An input iterator `i` supports the expression
11
  `*i`, resulting in a value of some object type `T`, called the *value
12
+ type* of the iterator. An output iterator `i` has a non-empty set of
13
+ types that are *writable* to the iterator; for each such type `T`, the
14
+ expression `*i = o` is valid where `o` is a value of type `T`. An
15
+ iterator `i` for which the expression `(*i).m` is well-defined supports
16
  the expression `i->m` with the same semantics as `(*i).m`. For every
17
  iterator type `X` for which equality is defined, there is a
18
  corresponding signed integer type called the *difference type* of the
19
  iterator.
20
 
 
41
  be used whenever a forward iterator is specified; Random access
42
  iterators also satisfy all the requirements of bidirectional iterators
43
  and can be used whenever a bidirectional iterator is specified.
44
 
45
  Iterators that further satisfy the requirements of output iterators are
46
+ called *mutable iterators*. Nonmutable iterators are referred to as
47
+ *constant iterators*.
48
+
49
+ In addition to the requirements in this subclause, the nested
50
+ *typedef-name*s specified in [[iterator.traits]] shall be provided for
51
+ the iterator type.
52
+
53
+ [*Note 1*: Either the iterator type must provide the *typedef-name*s
54
+ directly (in which case `iterator_traits` pick them up automatically),
55
+ or an `iterator_traits` specialization must provide them. — *end note*]
56
+
57
+ Iterators that further satisfy the requirement that, for integral values
58
+ `n` and dereferenceable iterator values `a` and `(a + n)`, `*(a + n)` is
59
+ equivalent to `*(addressof(*a) + n)`, are called *contiguous iterators*.
60
+
61
+ [*Note 2*: For example, the type “pointer to `int`” is a contiguous
62
+ iterator, but `reverse_iterator<int *>` is not. For a valid iterator
63
+ range [`a`,`b`) with dereferenceable `a`, the corresponding range
64
+ denoted by pointers is [`addressof(*a)`,`addressof(*a) + (b - a)`); `b`
65
+ might not be dereferenceable. — *end note*]
66
 
67
  Just as a regular pointer to an array guarantees that there is a pointer
68
  value pointing past the last element of the array, so for any iterator
69
  type there is an iterator value that points past the last element of a
70
  corresponding sequence. These values are called *past-the-end* values.
71
  Values of an iterator `i` for which the expression `*i` is defined are
72
  called *dereferenceable*. The library never assumes that past-the-end
73
  values are dereferenceable. Iterators can also have singular values that
74
+ are not associated with any sequence.
75
+
76
+ [*Example 1*: After the declaration of an uninitialized pointer `x` (as
77
+ with `int* x;`), `x` must always be assumed to have a singular value of
78
+ a pointer. *end example*]
79
+
80
+ Results of most expressions are undefined for singular values; the only
81
+ exceptions are destroying an iterator that holds a singular value, the
82
+ assignment of a non-singular value to an iterator that holds a singular
83
+ value, and, for iterators that satisfy the `DefaultConstructible`
84
+ requirements, using a value-initialized iterator as the source of a copy
85
+ or move operation.
86
+
87
+ [*Note 3*: This guarantee is not offered for default-initialization,
88
+ although the distinction only matters for types with trivial default
89
+ constructors such as pointers or aggregates holding
90
+ pointers. — *end note*]
91
+
92
+ In these cases the singular value is overwritten the same way as any
93
+ other value. Dereferenceable values are always non-singular.
94
 
95
  An iterator `j` is called *reachable* from an iterator `i` if and only
96
  if there is a finite sequence of applications of the expression `++i`
97
  that makes `i == j`. If `j` is reachable from `i`, they refer to
98
  elements of the same sequence.
 
120
  `const X`, `difference_type` and `reference` refer to the types
121
  `iterator_traits<X>::difference_type` and
122
  `iterator_traits<X>::reference`, respectively, `n` denotes a value of
123
  `difference_type`, `u`, `tmp`, and `m` denote identifiers, `r` denotes a
124
  value of `X&`, `t` denotes a value of value type `T`, `o` denotes a
125
+ value of some type that is writable to the output iterator.
126
+
127
+ [*Note 4*: For an iterator type `X` there must be an instantiation of
128
+ `iterator_traits<X>` ([[iterator.traits]]). — *end note*]
129
 
130
  ### Iterator <a id="iterator.iterators">[[iterator.iterators]]</a>
131
 
132
  The `Iterator` requirements form the basis of the iterator concept
133
  taxonomy; every iterator satisfies the `Iterator` requirements. This set
134
  of requirements specifies operations for dereferencing and incrementing
135
  an iterator. Most algorithms will require additional operations to
136
  read ([[input.iterators]]) or write ([[output.iterators]]) values, or
137
  to provide a richer set of iterator movements ([[forward.iterators]],
138
+ [[bidirectional.iterators]], [[random.access.iterators]]).
139
 
140
  A type `X` satisfies the `Iterator` requirements if:
141
 
142
  - `X` satisfies the `CopyConstructible`, `CopyAssignable`, and
143
  `Destructible` requirements ([[utility.arg.requirements]]) and
 
146
  have the indicated semantics.
147
 
148
  ### Input iterators <a id="input.iterators">[[input.iterators]]</a>
149
 
150
  A class or pointer type `X` satisfies the requirements of an input
151
+ iterator for the value type `T` if `X` satisfies the `Iterator` (
152
  [[iterator.iterators]]) and `EqualityComparable` (Table 
153
+ [[tab:equalitycomparable]]) requirements and the expressions in Table 
154
  [[tab:iterator.input.requirements]] are valid and have the indicated
155
  semantics.
156
 
157
  In Table  [[tab:iterator.input.requirements]], the term *the domain of
158
  `==`* is used in the ordinary mathematical sense to denote the set of
159
  values over which `==` is (required to be) defined. This set can change
160
  over time. Each algorithm places additional requirements on the domain
161
  of `==` for the iterator values it uses. These requirements can be
162
+ inferred from the uses that algorithm makes of `==` and `!=`.
 
 
 
163
 
164
+ [*Example 1*: The call `find(a,b,x)` is defined only if the value of
165
+ `a` has the property *p* defined as follows: `b` has property *p* and a
166
+ value `i` has property *p* if (`*i==x`) or if (`*i!=x` and `++i` has
167
+ property *p*). — *end example*]
168
+
169
+ [*Note 1*: For input iterators, `a == b` does not imply `++a == ++b`.
170
+ (Equality does not guarantee the substitution property or referential
171
  transparency.) Algorithms on input iterators should never attempt to
172
  pass through the same iterator twice. They should be *single pass*
173
+ algorithms. Value type `T` is not required to be a `CopyAssignable` type
174
+ (Table  [[tab:copyassignable]]). These algorithms can be used with
175
+ istreams as the source of the input data through the `istream_iterator`
176
+ class template. — *end note*]
177
 
178
  ### Output iterators <a id="output.iterators">[[output.iterators]]</a>
179
 
180
  A class or pointer type `X` satisfies the requirements of an output
181
  iterator if `X` satisfies the `Iterator` requirements (
182
  [[iterator.iterators]]) and the expressions in Table 
183
  [[tab:iterator.output.requirements]] are valid and have the indicated
184
  semantics.
185
 
186
+ [*Note 1*: The only valid use of an `operator*` is on the left side of
187
+ the assignment statement. *Assignment through the same value of the
188
+ iterator happens only once.* Algorithms on output iterators should never
189
+ attempt to pass through the same iterator twice. They should be *single
190
+ pass* algorithms. Equality and inequality might not be defined.
191
+ Algorithms that take output iterators can be used with ostreams as the
192
+ destination for placing data through the `ostream_iterator` class as
193
+ well as with insert iterators and insert pointers. — *end note*]
194
 
195
  ### Forward iterators <a id="forward.iterators">[[forward.iterators]]</a>
196
 
197
  A class or pointer type `X` satisfies the requirements of a forward
198
  iterator if
199
 
200
  - `X` satisfies the requirements of an input iterator (
201
  [[input.iterators]]),
202
+ - `X` satisfies the `DefaultConstructible` requirements (
203
  [[utility.arg.requirements]]),
204
  - if `X` is a mutable iterator, `reference` is a reference to `T`; if
205
+ `X` is a constant iterator, `reference` is a reference to `const T`,
206
  - the expressions in Table  [[tab:iterator.forward.requirements]] are
207
  valid and have the indicated semantics, and
208
  - objects of type `X` offer the multi-pass guarantee, described below.
209
 
210
+ The domain of `==` for forward iterators is that of iterators over the
211
  same underlying sequence. However, value-initialized iterators may be
212
  compared and shall compare equal to other value-initialized iterators of
213
+ the same type.
214
+
215
+ [*Note 1*: Value-initialized iterators behave as if they refer past the
216
+ end of the same empty sequence. — *end note*]
217
 
218
  Two dereferenceable iterators `a` and `b` of type `X` offer the
219
  *multi-pass guarantee* if:
220
 
221
  - `a == b` implies `++a == ++b` and
222
  - `X` is a pointer type or the expression `(void)++X(a), *a` is
223
  equivalent to the expression `*a`.
224
 
225
+ [*Note 2*: The requirement that `a == b` implies `++a == ++b` (which is
226
+ not true for input and output iterators) and the removal of the
227
+ restrictions on the number of the assignments through a mutable iterator
228
+ (which applies to output iterators) allows the use of multi-pass
229
+ one-directional algorithms with forward iterators. — *end note*]
230
 
231
  If `a` and `b` are equal, then either `a` and `b` are both
232
  dereferenceable or else neither is dereferenceable.
233
 
234
  If `a` and `b` are both dereferenceable, then `a == b` if and only if
 
239
  A class or pointer type `X` satisfies the requirements of a
240
  bidirectional iterator if, in addition to satisfying the requirements
241
  for forward iterators, the following expressions are valid as shown in
242
  Table  [[tab:iterator.bidirectional.requirements]].
243
 
244
+ [*Note 1*: Bidirectional iterators allow algorithms to move iterators
245
+ backward as well as forward. — *end note*]
246
 
247
  ### Random access iterators <a id="random.access.iterators">[[random.access.iterators]]</a>
248
 
249
  A class or pointer type `X` satisfies the requirements of a random
250
  access iterator if, in addition to satisfying the requirements for