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 constrains 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.
10
+
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
12
-
Consider the following example, which defines a concept to prevent instantiating a template with a type that doesn't support division:
12
+
Consider the following example, which defines a concept to prevent instantiating the template with a type that doesn't support division:
13
13
14
14
```cpp
15
15
// requires /std:c++20 or later
@@ -48,9 +48,9 @@ int main()
48
48
}
49
49
```
50
50
51
-
When you pass the compiler switch `/diagnostics:caret` to Visual Studio 2022 version 17.4 or later, the error that concept `dividable<char*>` evaluated to false will point directly to the expression requirement `(a / b)` that failed.
51
+
When you pass the compiler switch `/diagnostics:caret` to Visual Studio 2022 version 17.4 preview 4 or later, the error that concept `dividable<char*>` evaluated to false will point directly to the expression requirement `(a / b)` that failed.
52
52
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.
53
+
Iterator concepts are defined in the `std` namespace, and are 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
55
There are six categories of iterators. They're directly related to the categories of ranges listed under [Range concepts](ranges.md#range-concepts).
56
56
@@ -65,18 +65,18 @@ In the following table, "Types" refers to the types of collections/iterators tha
|[`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`|
68
-
|[`output_iterator`](#output_iterator)<sup>C++20</sup> |Test for an iterator that you can write to. | Forward | Write | no |`ostream`, `inserter`|
69
-
|[`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`|
70
-
|[`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`|
71
-
|[`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`. |
72
-
|[`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`|
73
-
|[`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
+
|[`output_iterator`](#output_iterator)<sup>C++20</sup> |Specifies an iterator that you can write to. | Forward | Write | no |`ostream`, `inserter`|
69
+
|[`input_iterator`](#input_iterator)<sup>C++20</sup> |Specifies an iterator that you can read from once. | Forward | Read | no |`istream`, `istreambuf_iterator`|
70
+
|[`forward_iterator`](#forward_iterator)<sup>C++20</sup> |Specifies an iterator that can read (and possibly write) multiple times. | Forward | Read/write | yes |`vector`, `list`|
71
+
|[`bidirectional_iterator`](#bidirectional_iterator)<sup>C++20</sup> |Specifies an iterator that you can read and write both forwards and backwards. | Forward/backward | Read/write | yes |`list`, `set`, `multiset`, `map`, and `multimap`. |
72
+
|[`random_access_iterator`](#random_access_iterator)<sup>C++20</sup> |Specifies an iterator that you can read and write by index. | Forward/Backward | Read/write | yes |`vector`, `array`, `deque`|
73
+
|[`contiguous_iterator`](#contiguous_iterator)<sup>C++20</sup> |Specifies an iterator whose elements are sequential in memory, are the same size, and can be accessed using pointer arithmetic. | Forward/backward | Read/write | yes |`array`, `vector``string`.|
74
74
75
75
Other iterator concepts include:
76
76
77
77
| Iterator concept | Description |
78
78
|--|--|
79
-
|[`sentinel_for`](#sentinel_for)<sup>C++20</sup> |Test that a type is a sentinel for an iterator type. |
79
+
|[`sentinel_for`](#sentinel_for)<sup>C++20</sup> |Specifies that a type is a sentinel for an iterator type. |
80
80
|[`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. |
81
81
82
82
## `bidirectional_iterator`
@@ -103,7 +103,7 @@ The iterator to test to see if it's a `bidirectional_iterator`.
103
103
104
104
A `bidirectional_iterator` has the capabilities of a `forward_iterator`, but can also iterate backwards.
105
105
106
-
Some examples of containers that can be used with a `bidirectional_iterator` are `set`, `vector`, and `list`.
106
+
Some examples of containers that can be used with a `bidirectional_iterator` are `set`, `multiset`, `map`, `multimap`, `vector`, and `list`.
107
107
108
108
### Example: `bidirectional_iterator`
109
109
@@ -126,7 +126,7 @@ int main()
126
126
127
127
## `contiguous_iterator`
128
128
129
-
Specifies an iterator whose elements are sequential in memory and can be accessed using pointer arithmetic.
129
+
Specifies an iterator whose elements are sequential in memory, are the same size, and can be accessed using pointer arithmetic.
130
130
131
131
```cpp
132
132
template<classI>
@@ -171,7 +171,7 @@ int main()
171
171
172
172
## `forward_iterator`
173
173
174
-
Has the capabilities of an `input_iterator` and an `output_iterator`. Also supports iterating over a collection multiple times.
174
+
Has the capabilities of an `input_iterator` and an `output_iterator`. Supports iterating over a collection multiple times.
175
175
176
176
```cpp
177
177
template<classI>
@@ -191,7 +191,7 @@ The iterator to test to see if it's a `forward_iterator`.
191
191
192
192
A `forward_iterator` can only move forward.
193
193
194
-
Some examples of containers that can be used with a `forward_iterator` are `unordered_set`, `unordered_multiset`, `unordered_map`, and `unordered_multimap`.
194
+
Some examples of containers that can be used with a `forward_iterator` are `vector`, `list`, `unordered_set`, `unordered_multiset`, `unordered_map`, and `unordered_multimap`.
195
195
196
196
### Example: `forward_iterator`
197
197
@@ -233,7 +233,7 @@ The type to test to see if it's an `input_iterator`.
233
233
234
234
### Remarks
235
235
236
-
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.
236
+
Calling `begin()` on an `input_iterator` more than once results in undefined behavior. A type that only models `input_iterator`isn't multi-pass. 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
237
238
238
### Example: `input_iterator`
239
239
@@ -294,7 +294,7 @@ int main()
294
294
295
295
## `output_iterator`
296
296
297
-
An `output_iterator` is a type that you can write to.
297
+
An `output_iterator` is an iterator that you can write to.
Copy file name to clipboardExpand all lines: docs/standard-library/iterator.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -89,18 +89,18 @@ 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 directly 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 also 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, the same size, 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. |
101
101
|[`output_iterator`](iterator-concepts.md#output_iterator)| Specifies an iterator that you can write to. |
102
-
|[`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. |
102
+
|[`random_access_iterator`](iterator-concepts.md#random_access_iterator)<sup>C++20</sup> | Specifies an iterator that you can read and write by index. |
103
+
|[`sentinel_for`](iterator-concepts.md#sentinel_for)<sup>C++20</sup> |Specifies a sentinel for an iterator type. |
104
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/range-adaptors.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
@@ -50,7 +50,7 @@ When a range adaptor produces a view, it doesn't incur the cost of transforming
50
50
51
51
Creating a view is preparation to do work in the future. In the previous example, creating the view doesn't result in finding all the elements divisible by three or squaring those elements. Work happens only when you access an element in the view.
52
52
53
-
Elements of a view are usually the actual elements of the range used to create the view. The view usually doesn't own the elements; it just refers to them. Although [`owning_view`](owning-view-class.md) is an exception. Changing an element changes that element in the range that the view was created from. The following example shows this behavior:
53
+
Elements of a view are usually the actual elements of the range used to create the view. The view usually doesn't own the elements; it just refers to them, with the exception of [`owning_view`](owning-view-class.md). Changing an element changes that element in the range that the view was created from. The following example shows this behavior:
Concepts are a C++20 language feature that constrains 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.
10
+
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
12
12
Consider the following example, which defines a concept to prevent instantiating a template with a type that doesn't support division:
13
13
@@ -48,24 +48,23 @@ int main()
48
48
}
49
49
```
50
50
51
-
When you pass the compiler switch `/diagnostics:caret` to Visual Studio 2022 version 17.4 or later, the error that concept `dividable<char*>` evaluated to false will point directly to the expression requirement `(a / b)` that failed.
51
+
When you pass the compiler switch `/diagnostics:caret` to Visual Studio 2022 version 17.4 preview 4, or later, the error that concept `dividable<char*>` evaluated to false will point directly to the expression requirement `(a / b)` that failed.
52
52
53
-
Range concepts are defined in the `std::ranges` namespace as declared in the `<ranges>` header file. They're used in the declarations of [range adaptors](range-adaptors.md), [views](view-classes.md), and so on.
53
+
Range concepts are defined in the `std::ranges` namespace, and declared in the `<ranges>` header file. They're used in the declarations of [range adaptors](range-adaptors.md), [views](view-classes.md), and so on.
54
54
55
55
There are six categories of ranges. They're related to the categories of iterators listed in [`<iterator>` concepts](iterator-concepts.md). In order of increasing capability, the categories are:
56
56
57
57
| Range concept | Description |
58
58
|--|--|
59
-
|[`output_range`](#output_range)| Specifies a range that you can write to. |
60
-
|[`input_range`](#input_range)| Specifies a range that you can read from at least once.|
61
-
|[`forward_range`](#forward_range)| Specifies a range that can read (and possibly write) multiple times. |
62
-
|[`bidirectional_range`](#bidirectional_range)| Specifies a range that can read and write both forwards and backwards. |
63
-
|[`random_access_range`](#random_access_range)| Specifies a range that can read and write by index. |
64
-
|[`contiguous_range`](#contiguous_range)| Specifies a range whose elements are sequential in memory and can be accessed using pointer arithmetic. |
59
+
|[`output_range`](#output_range)<br>[`input_range`](#input_range)| Specifies a range that you can write to.<br>Specifies a range that you can read from once. |
60
+
|[`forward_range`](#forward_range)| Specifies a range that you can read (and possibly write) multiple times. |
61
+
|[`bidirectional_range`](#bidirectional_range)| Specifies a range that you can read and write both forwards and backwards. |
62
+
|[`random_access_range`](#random_access_range)| Specifies a range that you can read and write by index. |
63
+
|[`contiguous_range`](#contiguous_range)| Specifies a range whose elements are sequential in memory, are the same size, and can be accessed using pointer arithmetic. |
65
64
66
-
In the preceding table, concepts are listed in order of increasing capability. A range that meets the requirements of a concept generally meets the requirements of the concepts in the rows that precede it. For example, a `random_access_range` has the capability of a `bidirectional_range`, `forward_range`, `input_range`, and `output_range`. Except `input_range`, which doesn't have the capability of an `output_range` because it can't be written to.
65
+
In the preceding table, concepts are listed in order of increasing capability. A range that meets the requirements of a concept generally meets the requirements of the concepts in the rows that precede it. For example, a `random_access_range` has the capability of a `bidirectional_range`, `forward_range`, `input_range`, and `output_range`. The exception is `input_range`, which can't be written to, so it doesn't have the capabilities of `output_range`.
67
66
68
-
:::image type="content" source="media/ranges-iterator-hiearchy.svg" alt-text="Diagram of the ranges iterator hierarchy. input_range and output_range are the base. forward_range is next and refines both input_range and output_range. bidirectional_range refines forward_range. random_access_range refines bidirectional_range. Finally, contiguous_range refines random_access_range":::
67
+
:::image type="content" source="media/ranges-iterator-hiearchy.svg" alt-text="Diagram of the ranges iterator hierarchy. input_range and output_range are the most basic iterators. forward_range is next and refines both input_range and output_range. bidirectional_range refines forward_range. random_access_range refines bidirectional_range. Finally, contiguous_range refines random_access_range":::
69
68
70
69
Other range concepts include:
71
70
@@ -75,7 +74,7 @@ Other range concepts include:
75
74
|[`borrowed_range`](#borrowed_range)<sup>C++20</sup> | Specifies that the lifetime of the range's iterators aren't tied to the range's lifetime. |
76
75
|[`common_range`](#common_range)<sup>C++20</sup> | Specifies that the type of the range's iterator and the type of the range's sentinel are the same. |
77
76
|[`Simple_View`](#simple_view)<sup>C++20</sup> | Not an official concept defined as part of the standard library, but used as a helper concept on some interfaces. |
78
-
|[`sized_range`](#sized_range)<sup>C++20</sup> | Specifies a range that can provide the number of elements in a range efficiently. |
77
+
|[`sized_range`](#sized_range)<sup>C++20</sup> | Specifies a range that can provide its number of elements efficiently. |
79
78
|[`view`](#view)<sup>C++20</sup> | Specifies a type that has efficient (constant time) move construction, assignment, and destruction. |
80
79
|[`viewable_range`](#viewable_range)<sup>C++20</sup> | Specifies a type that either is a view or can be converted to one. |
81
80
@@ -208,7 +207,7 @@ This kind of range supports [`forward_iterator`](iterator-concepts.md#forward_it
208
207
209
208
## `input_range`
210
209
211
-
An `input_range` is a range that can be read from at least once.
210
+
An `input_range` is a range that can be read from once.
0 commit comments