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
Concepts are a C++20 language feature that constrain template parameters at compile time. They help prevent incorrect template instantiation, specify template argument requirements in a readable form, and provide more succinct template related compiler errors.
11
11
@@ -52,17 +52,19 @@ 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). In order of increasing capability, the categories are:
55
+
There are six categories of iterators. They are directly related to the categories of ranges listed in [`<ranges>`](ranges.md#kinds-of-ranges).
56
56
57
-
| Iterator concept | Description |
58
-
|--|--|
59
-
DONE | [`input_or_output_iterator`](#input_or_output_iterator)<sup>C++20</sup> | The basis of the iterator concept taxonomy. |
60
-
DONE | [`output_iterator`](#output_iterator)<sup>C++20</sup> | Test for an iterator that you can write to. |
61
-
DONE | [`input_iterator`](#input_iterator)<sup>C++20</sup> | Test for an iterator that you can read from at least once. |
62
-
DONE | [`forward_iterator`](#forward_iterator)<sup>C++20</sup> | Test for an iterator that can read (and possibly write) multiple times. |
63
-
DONE | [`bidirectional_iterator`](#bidirectional_iterator)<sup>C++20</sup> | Test for an iterator that can read and write both forwards and backwards. |
64
-
DONE | [`random_access_iterator`](#random_access_iterator)<sup>C++20</sup> | Test for an iterator that can read and write by index. |
65
-
DONE | [`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. |
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.
58
+
59
+
| Iterator concept | Description | Direction | Read/write | Multi-pass | Example types that use this iterator |
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`|
66
68
67
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.
Defines predefined iterators and stream iterators, iterator primitives, and supporting templates.
11
11
12
-
The predefined iterators include insert and reverse adaptors.
13
-
14
-
There are three classes of insert iterator adaptors: front, back, and general. They provide insert semantics rather than overwrite semantics that the container member function iterators provide.
15
-
16
12
## Requirements
17
13
18
14
**Header:**`<iterator>`
@@ -21,30 +17,9 @@ There are three classes of insert iterator adaptors: front, back, and general. T
21
17
22
18
## Remarks
23
19
24
-
Iterators are a generalization of pointers that allow a C++ program to work with different data structures in a uniform way. Instead of operating on specific data types, algorithms operate on a range specified by a type of iterator. Any data structure that satisfies the requirements of the iterator can be operated upon by the algorithm. In C++20, there are 6 categories of iterators:
25
-
26
-
JTW fix this table up
20
+
Iterators are a generalization of pointers that allow a C++ program to work with different data structures in a uniform way. Instead of operating on specific data types, algorithms operate on a range of values as specified by a kind of iterator. Algorithms can operate on any data structure that satisfies the requirements of the iterator.
27
21
28
-
| Kind | Direction | Read/Write| Example types|
29
-
|---|---|---|---|
30
-
|`bidirectional_iterator`| Forward and backward | Read/Write |`list`, `set`, `multiset`, `map`, and `multimap`. |
31
-
|`contiguous_iterator`| Forward and backward | Read/Write | JTW |
| Bidirectional | Forward and backward | Read/Write | Yes |`list`, `set`, `multiset`, `map`, and `multimap`. |
45
-
| Random access | Any order | Read/Write | Yes |`vector`, `deque`, `string`, and `array`. |
46
-
47
-
Iterators are arranged in a hierarchy of capability. In the table above, output iterators are at the low end of the capability hierarchy, and random-access iterators are 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 can be used in place of a forward iterator, but not the other way around.
22
+
In C++20, there are 6 categories of iterators. Iterators are arranged in a hierarchy of capability. Their capabilities are specified by C++20 concepts. For a description of the various iterators and their capabilities, see [Iterator concepts](iterator-concepts.md)
48
23
49
24
Visual Studio has added extensions to C++ Standard Library iterators to support debugging for checked and unchecked iterators. For more information, see [Safe Libraries: C++ Standard Library](../standard-library/safe-libraries-cpp-standard-library.md).
50
25
@@ -114,17 +89,19 @@ Visual Studio has added extensions to C++ Standard Library iterators to support
114
89
115
90
## Concepts
116
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).
93
+
117
94
| Iterator concept | Description |
118
95
|--|--|
119
-
|[`bidirectional_iterator`](iterator-concepts.md#bidirectional_iterator)| Specifies an iterator that can read and write both forwards and backwards. |
120
-
|[`contiguous_iterator`](iterator-concepts.md#contiguous_iterator)| Specifies an iterator whose elements are sequential in memory and can be accessed using pointer arithmetic. |
121
-
|[`forward_iterator`](iterator-concepts.md#forward_iterator)| Specifies an iterator that can read (and possibly write) multiple times. |
122
-
|[`input_iterator`](iterator-concepts.md#input_iterator)| Specifies an iterator that you can read from at least once. |
123
-
|[`input_or_output_iterator`](iterator-concepts.md#input_or_output_iterator)| The basis of the iterator concept taxonomy. |
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. |
98
+
|[`forward_iterator`](iterator-concepts.md#forward_iterator)<sup>C++20</sup>| Specifies an iterator that can read (and possibly write) multiple times. |
99
+
|[`input_iterator`](iterator-concepts.md#input_iterator)<sup>C++20</sup>| Specifies an iterator that you can read from at least once. |
100
+
|[`input_or_output_iterator`](iterator-concepts.md#input_or_output_iterator)<sup>C++20</sup>| The basis of the iterator concept taxonomy. |
124
101
|[`output_iterator`](iterator-concepts.md#output_iterator)| Specifies an iterator that you can write to. |
125
-
|[`random_access_iterator`](iterator-concepts.md#random_access_iterator)| Specifies an iterator that can read and write by index. |
|[`random_access_iterator`](iterator-concepts.md#random_access_iterator)<sup>C++20</sup>| Specifies an iterator that can read and write by index. |
103
+
|[`sentinel_for`](iterator-concepts.md#sentinel_for)<sup>C++20</sup> |Test that a type is a sentinel for an iterator type.|
104
+
|[`sized_sentinel_for`](iterator-concepts.md#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.|
Copy file name to clipboardExpand all lines: docs/standard-library/ranges.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
@@ -116,7 +116,7 @@ The range algorithms are almost identical to the corresponding iterator-pair alg
116
116
117
117
### Kinds of ranges
118
118
119
-
How you can iterate over the elements of a range depends on its underlying iterator type. The iterator type a range requires is specified as a C++20 concept.
119
+
How you can iterate over the elements of a range depends on its underlying iterator type. Ranges use C++ concepts to specify the iterator they support.
120
120
121
121
In C++20, to say that concept *X* refines concept *Y* means that everything that satisfies concept *Y* also satisfies concept *X*. For example: *car*, *bus*, and *truck* all refine *vehicle*.
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
@@ -146,7 +146,7 @@ Each view class topic has a **Characteristics** section after the syntax section
146
146
147
147
### Ranges iterator hierarchy
148
148
149
-
In the **Characteristics** section of each view class topic, the iterator category in **Underlying range** and **View iterator category** refers to the kind of iterators that ranges and views support. Ranges iterators are categorized into six levels of capability, which are identified by C++20 concepts. That hierarchy, in increasing order of capability, is:
149
+
In the **Characteristics** section of each view class topic, the iterator category in **Underlying range** and **View iterator category** refers to the kind of iterator that the range/view supports. Ranges iterators are categorized into six levels of capability, which are identified by C++20 concepts. That hierarchy, in increasing order of capability, is:
0 commit comments