Skip to content

Commit f614a95

Browse files
TylerMSFTTylerMSFT
authored andcommitted
edits
1 parent eecf89e commit f614a95

File tree

6 files changed

+40
-41
lines changed

6 files changed

+40
-41
lines changed

docs/standard-library/iterator-concepts.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ helpviewer_keywords: ["std::ranges [C++], ranges::range", "std::ranges [C++], ra
77
---
88
# Iterator concepts
99

10-
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.
1111

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:
1313

1414
```cpp
1515
// requires /std:c++20 or later
@@ -48,9 +48,9 @@ int main()
4848
}
4949
```
5050

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.
5252

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.
5454

5555
There are six categories of iterators. They're directly related to the categories of ranges listed under [Range concepts](ranges.md#range-concepts).
5656

@@ -65,18 +65,18 @@ In the following table, "Types" refers to the types of collections/iterators tha
6565
| Iterator concept | Description | Direction | Read/write | Multi-pass | Types |
6666
|--|--|--|--|--|--|
6767
| [`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`.|
7474

7575
Other iterator concepts include:
7676

7777
| Iterator concept | Description |
7878
|--|--|
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. |
8080
| [`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. |
8181

8282
## `bidirectional_iterator`
@@ -103,7 +103,7 @@ The iterator to test to see if it's a `bidirectional_iterator`.
103103
104104
A `bidirectional_iterator` has the capabilities of a `forward_iterator`, but can also iterate backwards.
105105
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`.
107107
108108
### Example: `bidirectional_iterator`
109109
@@ -126,7 +126,7 @@ int main()
126126

127127
## `contiguous_iterator`
128128

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.
130130

131131
```cpp
132132
template<class I>
@@ -171,7 +171,7 @@ int main()
171171

172172
## `forward_iterator`
173173

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.
175175

176176
```cpp
177177
template<class I>
@@ -191,7 +191,7 @@ The iterator to test to see if it's a `forward_iterator`.
191191

192192
A `forward_iterator` can only move forward.
193193

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`.
195195

196196
### Example: `forward_iterator`
197197

@@ -233,7 +233,7 @@ The type to test to see if it's an `input_iterator`.
233233
234234
### Remarks
235235
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.
237237
238238
### Example: `input_iterator`
239239
@@ -294,7 +294,7 @@ int main()
294294

295295
## `output_iterator`
296296

297-
An `output_iterator` is a type that you can write to.
297+
An `output_iterator` is an iterator that you can write to.
298298

299299
```cpp
300300
template<class I, class T>
@@ -333,7 +333,7 @@ int main()
333333
std::cout << std::boolalpha << std::output_iterator<std::vector<int>::iterator, int> << "\n"; // outputs "true"
334334
335335
// another way to test
336-
std::vector<int> v = { 0,1,2,3,4,5 };
336+
std::vector<int> v = {0,1,2,3,4,5};
337337
std::cout << std::boolalpha << std::output_iterator<decltype(v)::iterator, int>; // outputs true
338338
}
339339
```
@@ -392,7 +392,7 @@ int main()
392392

393393
## `sentinel_for`
394394

395-
Test that a type is a sentinel for an iterator.
395+
Specifies that a type is a sentinel for an iterator.
396396

397397
```cpp
398398
template<class S, class I>

docs/standard-library/iterator.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,18 @@ Visual Studio has added extensions to C++ Standard Library iterators to support
8989

9090
## Concepts
9191

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).
9393

9494
| Iterator concept | Description |
9595
|--|--|
9696
| [`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. |
9898
| [`forward_iterator`](iterator-concepts.md#forward_iterator)<sup>C++20</sup> | Specifies an iterator that can read (and possibly write) multiple times. |
9999
| [`input_iterator`](iterator-concepts.md#input_iterator)<sup>C++20</sup> | Specifies an iterator that you can read from at least once. |
100100
| [`input_or_output_iterator`](iterator-concepts.md#input_or_output_iterator)<sup>C++20</sup> | The basis of the iterator concept taxonomy. |
101101
| [`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. |
104104
| [`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. |
105105

106106
## See also

docs/standard-library/range-adaptors.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ When a range adaptor produces a view, it doesn't incur the cost of transforming
5050

5151
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.
5252

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:
5454

5555
```cpp
5656
#include <algorithm>

docs/standard-library/range-concepts.md

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ helpviewer_keywords: ["std::ranges [C++], ranges::range", "std::ranges [C++], ra
77
---
88
# `<ranges>` concepts
99

10-
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.
1111

1212
Consider the following example, which defines a concept to prevent instantiating a template with a type that doesn't support division:
1313

@@ -48,24 +48,23 @@ int main()
4848
}
4949
```
5050

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.
5252

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.
5454

5555
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:
5656

5757
| Range concept | Description |
5858
|--|--|
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. |
6564

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`.
6766

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":::
6968

7069
Other range concepts include:
7170

@@ -75,7 +74,7 @@ Other range concepts include:
7574
| [`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. |
7675
| [`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. |
7776
| [`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. |
7978
| [`view`](#view)<sup>C++20</sup> | Specifies a type that has efficient (constant time) move construction, assignment, and destruction. |
8079
| [`viewable_range`](#viewable_range)<sup>C++20</sup> | Specifies a type that either is a view or can be converted to one. |
8180

@@ -208,7 +207,7 @@ This kind of range supports [`forward_iterator`](iterator-concepts.md#forward_it
208207

209208
## `input_range`
210209

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.
212211

213212
```cpp
214213
template<class T>

0 commit comments

Comments
 (0)