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
@@ -52,28 +52,26 @@ When you pass the compiler switch `/diagnostics:caret` to Visual Studio 2022 ver
52
52
53
53
Iterator concepts are defined in the `std` namespace as declared in the `<iterator>` header file. They're used in the declarations of [range adaptors](range-adaptors.md), [views](view-classes.md), and so on.
54
54
55
-
There are six categories of iterators. They are directly related to the categories of ranges listed in [`<ranges>`](ranges.md#kinds-of-ranges).
55
+
There are six categories of iterators. They are directly related to the categories of ranges listed under [Range concepts](ranges.md#range-concepts).
56
56
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 to the rule that iterators higher in the hierarchy can generally be used in place of those that are lower is `input_iterator`, which can't be used in place of `output_iterator` because it can't write.
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
59
| Iterator concept | Description | Direction | Read/write | Multi-pass | Example types that use this iterator |
60
60
|--|--|--|--|--|--|
61
-
|[`input_or_output_iterator`](#input_or_output_iterator)<sup>C++20</sup> | The basis of the iterator concept taxonomy. | Forward | Read or write | Single-pass |`std::istream_iterator`, `std::ostream_iterator`|
62
-
|[`output_iterator`](#output_iterator)<sup>C++20</sup> | Test for an iterator that you can write to. | Forward | Write | Single-pass |`ostream`, `inserter`|
63
-
|[`input_iterator`](#input_iterator)<sup>C++20</sup> | Test for an iterator that you can read from at least once. | Forward | Read | Single-pass |`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 | Multi-pass |`vector::iterator`, `list::iterator`|
65
-
|[`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 | Multi-pass |`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. | Read/write | Multi-pass |`vector::iterator`, `array::iterator`|
67
-
|[`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. | Read/write | Multi-pass |`array`, `vector`|
68
-
69
-
An iterator that meets the requirements of a concept generally meets the requirements of the concepts in the rows that precede it in the previous table. For example, a `random_access_iterator` has the capability of a `bidirectional_iterator`, `forward_iterator`, `input_iterator`, and `output_iterator`. An exception is `input_iterator` which doesn't have the capability of an `output_iterator` because it can't be written to.
61
+
|[`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`|
62
+
|[`output_iterator`](#output_iterator)<sup>C++20</sup> | Test for an iterator that you can write to. | Forward | Write | no |`ostream`, `inserter`|
63
+
|[`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`|
65
+
|[`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`|
67
+
|[`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`.|
70
68
71
69
Other iterator concepts include:
72
70
73
71
| Iterator concept | Description |
74
72
|--|--|
75
-
DONE | [`sentinel_for`](#sentinel_for)<sup>C++20</sup> | Test that a type is a sentinel for an iterator type. |
76
-
DONE | [`sized_sentinel_for`](#sized_sentinel_for)<sup>C++20</sup> | Specifies that an iterator and its sentinel can be subtracted (using `-`) to find their difference in constant time. |
73
+
|[`sentinel_for`](#sentinel_for)<sup>C++20</sup> | Test that a type is a sentinel for an iterator type. |
74
+
|[`sized_sentinel_for`](#sized_sentinel_for)<sup>C++20</sup> | Specifies that an iterator and its sentinel can be subtracted (using `-`) to find their difference in constant time. |
77
75
78
76
## `bidirectional_iterator`
79
77
@@ -103,7 +101,7 @@ Some examples of containers that can be used with a `bidirectional_iterator` are
103
101
104
102
### Example: `bidirectional_iterator`
105
103
106
-
The following example shows that a `vector` of `int` has a `bidirectional_iterator`:
104
+
The following example uses the `bidirectional_iterator` concept to show that `vector<int>` has a `bidirectional_iterator`:
107
105
108
106
```cpp
109
107
// requires /std:c++20 or later
@@ -113,6 +111,10 @@ The following example shows that a `vector` of `int` has a `bidirectional_iterat
The type to test to see if it's a `contiguous_iterator`.
139
141
140
-
The elements of a `contiguous_iterator` are stored sequentially in memory and can be accessed using pointer arithmetic. For example, an array iterator is a `contiguous_iterator`.
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`.
141
143
142
144
### Remarks
143
145
@@ -147,7 +149,7 @@ Some examples of a `contiguous_iterator` are `std::array`, `std::vector`, and `s
147
149
148
150
### Example: `contiguous_iterator`
149
151
150
-
The following example shows that a vector is a `contiguous_iterator`:
152
+
The following example uses the `contiguous_iterator` concept to show that a `vector<int>` has a `contiguous_iterator`:
151
153
152
154
```cpp
153
155
// requires /std:c++20 or later
@@ -156,8 +158,11 @@ The following example shows that a vector is a `contiguous_iterator`:
156
158
157
159
int main()
158
160
{
159
-
// Show that vector has a contiguous_iterator
160
-
std::vector<int> v = {0,1,2,3,4,5};
161
+
// Show that vector<int> has a contiguous_iterator
A `random_access_iterator` can read or write by index.
@@ -319,13 +365,13 @@ The type to test to see if it's a `random_access_iterator`.
319
365
320
366
### Remarks
321
367
322
-
A `random_access_iterator` is the most flexible iterator. It has the capabilities of an `input_iterator`, `output_iterator`, `forward_iterator`, and `bidirectional_iterator`.
368
+
A `random_access_iterator` has the capabilities of an `input_iterator`, `output_iterator`, `forward_iterator`, and `bidirectional_iterator`.
323
369
324
370
Some examples of a `random_access_iterator` are `std::vector`, `std::array`, and `std::deque`.
325
371
326
372
### Example: `random_access_iterator`
327
373
328
-
The following example shows that a `vector` of `int` is a `random_access_iterator`:
374
+
The following example shows that a `vector<int>` has a `random_access_iterator`:
329
375
330
376
```cpp
331
377
// requires /std:c++20 or later
@@ -334,7 +380,12 @@ The following example shows that a `vector` of `int` is a `random_access_iterato
334
380
335
381
intmain()
336
382
{
383
+
// Show that vector<int> has a random_access_iterator
The sentinel type to test to see if it's a sentinel for `I`.
410
+
The type to test to see if it's a sentinel for `I`.
360
411
361
412
### Remarks
362
413
363
414
A sentinel is a type that can be compared to an iterator to determine if the iterator has reached the end. This concept determines if a type is a sentinel for one of the `input_or_output_iterator` types which includes `input_iterator`, `output_iterator`, `forward_iterator`, `bidirectional_iterator`, `random_access_iterator`, and `contiguous_iterator`.
364
415
365
416
### Example: `sentinel_for`
366
417
367
-
The following example shows that a `vector` of `int` is a `random_access_iterator`:
418
+
The following example uses the `sentinel_for` concept to show that `std::vector<int>::iterator` is a sentinel for `vector<int>`:
368
419
369
420
```cpp
370
421
// requires /std:c++20 or later
@@ -373,16 +424,16 @@ The following example shows that a `vector` of `int` is a `random_access_iterato
373
424
374
425
int main()
375
426
{
376
-
std::vector<int> v = { 1, 2, 3, 4, 5 };
427
+
std::vector<int> v = {0, 1, 2};
377
428
std::vector<int>::iterator i = v.begin();
378
-
// test if std::vector<int>::iterator is a sentinel for i
429
+
// show that vector<int>::iterator is a sentinel for vector<int>
Test that an iterator and its sentinel can be subtracted (using `-`) to find their difference in constant time.
436
+
Test that an iterator and its sentinel can be subtracted (using `-`) to find the difference in constant time.
386
437
387
438
```cpp
388
439
template<classS, class I>
@@ -407,7 +458,7 @@ The sentinel type to test.
407
458
408
459
### Example: `sized_sentinel_for`
409
460
410
-
The following example shows that a the sentinel for a `vector` can be subtracted from a vector iterator in constant time:
461
+
The following example uses the `sized_sentinel_for` concept to verify that the sentinel for a `vector<int>` can be subtracted from the vectors iterator in constant time:
411
462
412
463
```cpp
413
464
// requires /std:c++20 or later
@@ -416,12 +467,12 @@ The following example shows that a the sentinel for a `vector` can be subtracted
416
467
417
468
int main()
418
469
{
419
-
std::vector<int> v = { 1, 2, 3, 4, 5 };
470
+
std::vector<int> v = { 1, 2, 3 };
420
471
std::vector<int>::iterator i = v.begin();
421
472
std::vector<int>::iterator end = v.end();
422
-
// test if i can be subtracted from end in constant time
0 commit comments