You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/standard-library/iterator-concepts.md
+15-17Lines changed: 15 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -56,14 +56,18 @@ There are six categories of iterators. They're directly related to the categorie
56
56
57
57
The following iterator concepts are listed in order of increasing capability. `input_or_output_iterator` is at the low end of the capability hierarchy, and `contiguous_iterator` is at the high end. Iterators higher in the hierarchy can generally be used in place of those that are lower, but not vice-versa. For example, a `random_access_iterator` iterator can be used in place of a `forward_iterator`, but not the other way around. An exception is `input_iterator`, which can't be used in place of `output_iterator` because it can't write.
58
58
59
-
| Iterator concept | Description | Direction | Read/write | Multi-pass | Example types that use this iterator |
59
+
In the following table, "Multi-pass" refers to whether the iterator can revisit the same element more than once. For example, `vector::iterator` is a multi-pass iterator because you can make a copy of the iterator, read the elements in the collection, and then restore the iterator to the value in the copy, and revisit the same elements again. If an iterator is single-pass, you can only visit the elements in the collection once.
60
+
61
+
In the following table, "Types" refers to the types of collections/iterators that satisfy the concept.
|[`input_or_output_iterator`](#input_or_output_iterator)<sup>C++20</sup> | The basis of the iterator concept taxonomy. | Forward | Read or write | no |`std::istream_iterator`, `std::ostream_iterator`|
65
+
|[`input_or_output_iterator`](#input_or_output_iterator)<sup>C++20</sup> | The basis of the iterator concept taxonomy. | Forward | Read/write | no |`istream_iterator`, `ostream_iterator`|
62
66
|[`output_iterator`](#output_iterator)<sup>C++20</sup> | Test for an iterator that you can write to. | Forward | Write | no |`ostream`, `inserter`|
63
67
|[`input_iterator`](#input_iterator)<sup>C++20</sup> | Test for an iterator that you can read from at least once. | Forward | Read | no |`istream`, `istreambuf_iterator`|
64
-
|[`forward_iterator`](#forward_iterator)<sup>C++20</sup> | Test for an iterator that can read (and possibly write) multiple times. | Forward | Read/write | yes |`vector::iterator`, `list::iterator`|
68
+
|[`forward_iterator`](#forward_iterator)<sup>C++20</sup> | Test for an iterator that can read (and possibly write) multiple times. | Forward | Read/write | yes |`vector`, `list`|
65
69
|[`bidirectional_iterator`](#bidirectional_iterator)<sup>C++20</sup> | Test for an iterator that can read and write both forwards and backwards. | Forward/backward | Read/write | yes |`list`, `set`, `multiset`, `map`, and `multimap`. |
66
-
|[`random_access_iterator`](#random_access_iterator)<sup>C++20</sup> | Test for an iterator that can read and write by index. | Forward/Backward | Read/write | yes |`vector::iterator`, `array::iterator`, `deque::iterator`|
70
+
|[`random_access_iterator`](#random_access_iterator)<sup>C++20</sup> | Test for an iterator that can read and write by index. | Forward/Backward | Read/write | yes |`vector`, `array`, `deque`|
67
71
|[`contiguous_iterator`](#contiguous_iterator)<sup>C++20</sup> | Test for an iterator whose elements are sequential in memory and can be accessed using pointer arithmetic. | Forward/backward | Read/write | yes |`array`, `vector``string`.|
68
72
69
73
Other iterator concepts include:
@@ -97,7 +101,7 @@ The iterator to test to see if it's a `bidirectional_iterator`.
97
101
98
102
A `bidirectional_iterator` has the capabilities of a `forward_iterator`, but can also iterate backwards.
99
103
100
-
Some examples of containers that can be used with a `bidirectional_iterator` are `std::set`, `std::vector`, and `std::list`.
104
+
Some examples of containers that can be used with a `bidirectional_iterator` are `set`, `vector`, and `list`.
101
105
102
106
### Example: `bidirectional_iterator`
103
107
@@ -139,13 +143,9 @@ template<class I>
139
143
*`I`*\
140
144
The type to test to see if it's a `contiguous_iterator`.
141
145
142
-
The elements of a `contiguous_iterator` are stored sequentially in memory and can be accessed using pointer arithmetic. A `std::array` has a `contiguous_iterator`.
143
-
144
146
### Remarks
145
147
146
-
A `contiguous_iterator` can be accessed by pointer arithmetic because the elements are laid out sequentially in memory and are the same size.
147
-
148
-
Some examples of a `contiguous_iterator` are `std::array`, `std::vector`, and `std::string`.
148
+
A `contiguous_iterator` can be accessed by pointer arithmetic because the elements are laid out sequentially in memory and are the same size. Some examples of a `contiguous_iterator` are `array`, `vector`, and `string`.
149
149
150
150
### Example: `contiguous_iterator`
151
151
@@ -189,7 +189,7 @@ The iterator to test to see if it's a `forward_iterator`.
189
189
190
190
A `forward_iterator` can only move forward.
191
191
192
-
Some examples of containers that can be used with a `forward_iterator` are `std::unordered_set`, `std::unordered_multiset`, `std::unordered_map`, and `std::unordered_multimap`.
192
+
Some examples of containers that can be used with a `forward_iterator` are `unordered_set`, `unordered_multiset`, `unordered_map`, and `unordered_multimap`.
193
193
194
194
### Example: `forward_iterator`
195
195
@@ -231,9 +231,7 @@ The type to test to see if it's an `input_iterator`.
231
231
232
232
### Remarks
233
233
234
-
When a type meets the requirements of `input_iterator`:
235
-
236
-
- Calling `begin()` more than once on an `input_iterator` results in undefined behavior. This implies that if a type only models `input_iterator`, it isn't multi-pass and can read an element only once. Consider reading from standard input (`cin`) for example. In this case, you can only read the current element once and you can't re-read characters you've already read. You can only read an `input_iterator` forward, not backwards.
234
+
Calling `begin()` on an `input_iterator` more than once results in undefined behavior. This implies that if a type only models `input_iterator`, it isn't multi-pass and can read an element only once. Consider reading from standard input (`cin`) for example. In this case, you can only read the current element once and you can't re-read characters you've already read. An `input_iterator` only reads forward, not backwards.
237
235
238
236
### Example: `input_iterator`
239
237
@@ -368,7 +366,7 @@ The type to test to see if it's a `random_access_iterator`.
368
366
369
367
A `random_access_iterator` has the capabilities of an `input_iterator`, `output_iterator`, `forward_iterator`, and `bidirectional_iterator`.
370
368
371
-
Some examples of a `random_access_iterator` are `std::vector`, `std::array`, and `std::deque`.
369
+
Some examples of a `random_access_iterator` are `vector`, `array`, and `deque`.
372
370
373
371
### Example: `random_access_iterator`
374
372
@@ -416,7 +414,7 @@ A sentinel is a type that can be compared to an iterator to determine if the ite
416
414
417
415
### Example: `sentinel_for`
418
416
419
-
The following example uses the `sentinel_for` concept to show that `std::vector<int>::iterator` is a sentinel for `vector<int>`:
417
+
The following example uses the `sentinel_for` concept to show that `vector<int>::iterator` is a sentinel for `vector<int>`:
420
418
421
419
```cpp
422
420
// requires /std:c++20 or later
@@ -434,7 +432,7 @@ int main()
434
432
435
433
## `sized_sentinel_for`
436
434
437
-
Test that an iterator and its sentinel can be subtracted (using `-`) to find the difference in constant time.
435
+
Test that an iterator and its sentinel can be subtracted using `-` to find the difference, in constant time.
Copy file name to clipboardExpand all lines: docs/standard-library/iterator.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -89,12 +89,12 @@ Visual Studio has added extensions to C++ Standard Library iterators to support
89
89
90
90
## Concepts
91
91
92
-
The following concepts are defined in the `std` namespace. They apply to iterators, and are related to the iterator categories for ranges described in [`<ranges>` concepts](range-concepts.md).
92
+
The following concepts are defined in the `std` namespace. They apply to iterators, and are directly related to the iterator categories for ranges described in [`<ranges>` concepts](range-concepts.md).
93
93
94
94
| Iterator concept | Description |
95
95
|--|--|
96
96
|[`bidirectional_iterator`](iterator-concepts.md#bidirectional_iterator)<sup>C++20</sup> | Specifies an iterator that can read and write both forwards and backwards. |
97
-
|[`contiguous_iterator`](iterator-concepts.md#contiguous_iterator)<sup>C++20</sup> | Specifies an iterator whose elements are sequential in memory and can be accessed using pointer arithmetic. |
97
+
|[`contiguous_iterator`](iterator-concepts.md#contiguous_iterator)<sup>C++20</sup> | Specifies an iterator whose elements are sequential in memory, and can be accessed using pointer arithmetic. |
98
98
|[`forward_iterator`](iterator-concepts.md#forward_iterator)<sup>C++20</sup> | Specifies an iterator that can read (and possibly write) multiple times. |
99
99
|[`input_iterator`](iterator-concepts.md#input_iterator)<sup>C++20</sup> | Specifies an iterator that you can read from at least once. |
100
100
|[`input_or_output_iterator`](iterator-concepts.md#input_or_output_iterator)<sup>C++20</sup> | The basis of the iterator concept taxonomy. |
Copy file name to clipboardExpand all lines: docs/standard-library/view-classes.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -130,7 +130,7 @@ Many of these classes have corresponding [range adaptors](range-adaptors.md) in
130
130
Each view class topic has a **Characteristics** section after the syntax section. The **Characteristics** section has the following entries:
131
131
132
132
***Range adaptor**: A link to the range adaptor that creates the view. You typically use a range adaptor to create a view rather than create a view class directly, so it's listed here for convenience.
133
-
***Underlying range**: Views have different iterator requirements for the kind of underlying range that they can use. See [ranges iterator hierarchy](#ranges_iterator_hierarchy) for more information about the kinds of iterators.
133
+
***Underlying range**: Views have different iterator requirements for the kind of underlying range that they can use. See [ranges iterator hierarchy](#ranges-iterator-hierarchy) for more information about the kinds of iterators.
134
134
***View iterator category**: The iterator category of the view. When a view adapts a range, the iterator type for the view is typically the same as the iterator type of the underlying range. However, it might be different for some views. For example, `reverse_view` has a `bidirectional_iterator`, even if the underlying range has a `random_access_iterator`.
135
135
***Element type**: The type of the elements that the view's iterator returns.
136
136
***Sized**: Whether the view can return the number of elements that it refers to. Not all views can.
0 commit comments