Skip to content

Commit b67dfc8

Browse files
committed
edit pass: range-adaptor-and-view-classes-topics
1 parent a5dc937 commit b67dfc8

File tree

3 files changed

+84
-76
lines changed

3 files changed

+84
-76
lines changed

docs/standard-library/range-adaptors.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ helpviewer_keywords: ["std::ranges [C++], all", "std::ranges [C++], all_t", "std
99

1010
Range adapters create a *view* (one of the [view classes](view-classes.md) in the `std::views` namespace) from a range. We recommend that you use an adapter in `std::ranges::views` instead of creating the view types directly. The adapters are the intended way to access views. They're easier to use, and in some cases more efficient, than creating instances of the view types directly.
1111

12-
A *view* is a lightweight object that refers to elements from a range. A view can:
12+
A view is a lightweight object that refers to elements from a range. A view can:
1313

1414
- Consist of only certain elements from a range.
1515
- Represent a transformation of elements from a range.
@@ -83,9 +83,9 @@ Range adapters come in many forms. For example, there are range adapters that al
8383
- Transforming the elements in a range (`view::transform`).
8484
- Splitting a range (`view::split`).
8585

86-
Range adapters can be chained together (composed). That's where the power and flexibility of ranges is most apparent. Composing range adapters allows you to overcome a core problem with the previous Standard Template Library (STL) algorithms, which is that they aren't easy to chain together.
86+
Range adapters can be chained together (composed). That's where the power and flexibility of ranges are most apparent. Composing range adapters allows you to overcome a core problem with the previous Standard Template Library (STL) algorithms: that they aren't easy to chain together.
8787

88-
The following range adapters are available in the `std::views` namespace. The `std::views`namespace is a convenience alias for `std::ranges::views`.
88+
The following range adapters are available in the `std::views` namespace. The `std::views` namespace is a convenience alias for `std::ranges::views`.
8989

9090
| **Range adapter** | **Description** |
9191
|--|--|
@@ -115,7 +115,7 @@ In the previous table, a range adapter is typically described as taking a range
115115

116116
Range adapter functions are typically [function objects](https://eel.is/c++draft/function.objects), which look like function calls and enforce constraints on the types that can be passed.
117117

118-
You can pass range adapters and the result of pipe operations (`|`) to code that expects function objects. In the following example, the view created by the `split` range adapter is passed to the `transform` range adapter as if by a function call, because the `transform` range adapter is a function object.
118+
You can pass range adapters and the result of pipe operations (`|`) to code that expects function objects. In the following example, the view that the `split` range adapter creates is passed to the `transform` range adapter as if by a function call, because the `transform` range adapter is a function object.
119119

120120
```cpp
121121
std::map<int, string> x = {{0, "Hello, world"}, {42, "Goodbye, world"}};
@@ -144,18 +144,18 @@ The range to create the view from.
144144
### Return value
145145

146146
- If `rg` is already a view, a copy of `rg`.
147-
- If `rg` is a non-view lvalue, a [`ref_view`](ref-view-class.md) that refers to `rg`. (The lifetime of the view is tied to the lifetime of `rg`.)
147+
- If `rg` is a non-view `lvalue`, a [`ref_view`](ref-view-class.md) that refers to `rg`. (The lifetime of the view is tied to the lifetime of `rg`.)
148148
- If `rg` is a non-view `rvalue` such as a temporary object, or is the result of passing the range to `std::move`, an [`owning_view`](owning-view-class.md).
149149

150150
Use `std::views::all_t<decltype((rg))>` to get the type of the returned view.
151151

152152
### Remarks
153153

154-
This range adapter is the best way to convert a range into a view. One reason to create a view from a range is to pass it by value at low cost if passing the range by value could be expensive.
154+
This range adapter is the best way to convert a range into a view. One reason to create a view from a range is to pass it by value at low cost, if passing the range by value could be expensive.
155155

156156
Getting a view for a range is a useful alternative to passing a heavyweight range by value because views are inexpensive to create, copy, and destroy. A possible exception is `owning_view`, which is a view that owns the underlying range.
157157

158-
In general, the worst case scenario for destroying a view has `O(N)` complexity for the number of elements in the range. Even if you destroy `K` copies of view with `N` elements, the total complexity is still `O(N)` because the underlying range is destroyed only once.
158+
In general, the worst-case scenario for destroying a view has `O(N)` complexity for the number of elements in the range. Even if you destroy `K` copies of view with `N` elements, the total complexity is still `O(N)` because the underlying range is destroyed only once.
159159

160160
### Example: `all`
161161

@@ -344,12 +344,12 @@ If you specify more elements to drop than exist in the underlying range, an [`em
344344
345345
The returned view is typically, but not always, a specialization of [`drop_view`](drop-view-class.md). That is:
346346
347-
- If `V` is a specialization of [`empty_view`](empty-view-class.md) or a specialization of [`span`](span-class.md), [`basic_string_view`](basic-string-view-class.md), [`iota_view`](iota-view-class.md), or [`subrange`](subrange-class.md) that is both `random_access_range` and `sized_range`, the result is a specialization of `V`.
347+
- If `V` is a specialization of [`empty_view`](empty-view-class.md), or is a specialization of [`span`](span-class.md), [`basic_string_view`](basic-string-view-class.md), [`iota_view`](iota-view-class.md), or [`subrange`](subrange-class.md) that is both `random_access_range` and `sized_range`, the result is a specialization of `V`.
348348
- Otherwise, the result is a [`drop_view`](drop-view-class.md).
349349
350350
### Remarks
351351
352-
After it's created, the number of elements in the view stays the same even if the view it was created from changes. However, if the underlying view changes, accessing elements in the returned view might result in undefined behavior.
352+
After it's created, the number of elements in the view stays the same even if the view that it was created from changes. However, if the underlying view changes, accessing elements in the returned view might result in undefined behavior.
353353
354354
`drop` is the opposite of [`take`](#take).
355355
@@ -1198,7 +1198,7 @@ The number of elements to take from the front of `rg`.
11981198
11991199
The returned view is typically, but not always, a specialization of [`take_view`](take-view-class.md). Specifically:
12001200
1201-
- If `V` is a specialization of [`empty_view`](empty-view-class.md) or a specialization of [`span`](span-class.md), [`basic_string_view`](basic-string-view-class.md), [`iota_view`](iota-view-class.md), or [`subrange`](subrange-class.md) that is both `random_access_range` and `sized_range`, the result is a specialization of `V`.
1201+
- If `V` is a specialization of [`empty_view`](empty-view-class.md), or is a specialization of [`span`](span-class.md), [`basic_string_view`](basic-string-view-class.md), [`iota_view`](iota-view-class.md), or [`subrange`](subrange-class.md) that is both `random_access_range` and `sized_range`, the result is a specialization of `V`.
12021202
- Otherwise, the result is a [`take_view`](take-view-class.md).
12031203
12041204
### Remarks
@@ -1347,7 +1347,7 @@ A [`transform_view`](transform-view-class.md) that contains the transformed elem
13471347
13481348
For efficiency's sake, when you compose `filter` and `transform`, do the `filter` first so that you `transform` only the elements that you intend to keep.
13491349
1350-
The code shown earlier as "2\)" can be used with pipe syntax: `collection | transform(fun)`. Or you can use it with function call syntax: `transform(collection, fun)` or `transform(fun)(collection)`.
1350+
The code shown earlier as "2\)" can be used with pipe syntax: `collection | transform(fun)`. Or it can be used with function call syntax: `transform(collection, fun)` or `transform(fun)(collection)`.
13511351
13521352
### Example: `transform`
13531353

0 commit comments

Comments
 (0)