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
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.
10
+
Range adaptors 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 adaptor in `std::ranges::views` instead of creating the view types directly. The adaptors 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.
11
11
12
12
A view is a lightweight object that refers to elements from a range. A view can:
13
13
@@ -44,9 +44,9 @@ int main()
44
44
0 9 36 81
45
45
```
46
46
47
-
The first range adapter, `std::views::filter`, provides a view that contains the elements from `input` that are divisible by three. The other range adapter, `std::views::transform`, takes the view that contains the elements divisible by three and provides a view of the square of those elements.
47
+
The first range adaptor, `std::views::filter`, provides a view that contains the elements from `input` that are divisible by three. The other range adaptor, `std::views::transform`, takes the view that contains the elements divisible by three and provides a view of the square of those elements.
48
48
49
-
When a range adapter produces a view, it doesn't incur the cost of transforming every element in the range to produce that view. The cost to process an element in the view is paid only when you access that element.
49
+
When a range adaptor produces a view, it doesn't incur the cost of transforming every element in the range to produce that view. The cost to process an element in the view is paid only when you access that element.
50
50
51
51
Creating a view only prepares to do work in the future. In the previous example, creating the view doesn't result in finding all the elements divisible by three. It also doesn't square the elements that it finds. That work happens only when you access an element in the view.
52
52
@@ -77,17 +77,17 @@ int main()
77
77
}
78
78
```
79
79
80
-
Range adapters come in many forms. For example, there are range adapters that allow you to produce a view by:
80
+
Range adaptors come in many forms. For example, there are range adaptors that allow you to produce a view by:
81
81
82
82
- Filtering another range based on a predicate (`view::filter`).
83
83
- Transforming the elements in a range (`view::transform`).
84
84
- Splitting a range (`view::split`).
85
85
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, which is that they aren't easy to chain together.
86
+
Range adaptors can be chained together (composed). That's where the power and flexibility of ranges are most apparent. Composing range adaptors 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.
87
87
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 adaptors are available in the `std::views` namespace. The `std::views` namespace is a convenience alias for `std::ranges::views`.
89
89
90
-
| Range adapter| Description |
90
+
| Range adaptor| Description |
91
91
|--|--|
92
92
|[`all`](#all)<sup>C++20</sup> | Create a view that refers to a range and its elements. |
93
93
|[`common`](#common)<sup>C++20</sup> | Create a view that has the same iterator and sentinel types from a range that doesn't. |
@@ -107,15 +107,15 @@ The following range adapters are available in the `std::views` namespace. The `s
107
107
|[`transform`](#transform)<sup>C++20</sup> | Create a view of transformed elements from another view. |
108
108
|[`values`](#values)<sup>C++20</sup> | Create a view of the second index into each tuple-like value in a collection. |
109
109
110
-
In the previous table, a range adapter is typically described as taking a range and producing a view. To be precise, range adapters have a range argument that accepts one of the following:
110
+
In the previous table, a range adaptor is typically described as taking a range and producing a view. To be precise, range adaptors have a range argument that accepts one of the following:
111
111
112
112
- The `cv-unqualified` type models `view`, and the argument is an rvalue or is copyable.
113
113
- When you pass the argument as an lvalue, it must model `range` and live as long as the view.
114
114
- When you pass the argument as an rvalue, such as when calling [`owning_view`](owning-view-class.md), it must model `range` and `movable`.
115
115
116
-
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.
116
+
Range adaptor 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.
117
117
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.
118
+
You can pass range adaptors and the result of pipe operations (`|`) to code that expects function objects. In the following example, the view that the `split` range adaptor creates is passed to the `transform` range adaptor as if by a function call, because the `transform` range adaptor is a function object.
119
119
120
120
```cpp
121
121
std::map<int, string> x = {{0, "Hello, world"}, {42, "Goodbye, world"}};
@@ -151,7 +151,7 @@ Use `std::views::all_t<decltype((rg))>` to get the type of the returned view.
151
151
152
152
### Remarks
153
153
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 adaptor 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.
155
155
156
156
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.
157
157
@@ -209,7 +209,7 @@ The range to create the view from.
209
209
210
210
### Remarks
211
211
212
-
When an API requires the begin iterator and end sentinel to have the same type, and the view that you're using doesn't meet that requirement (or you don't know if it does), use this range adapter to create a `common_view`. It guarantees that the type of the begin iterator and the type of the end sentinel are the same.
212
+
When an API requires the begin iterator and end sentinel to have the same type, and the view that you're using doesn't meet that requirement (or you don't know if it does), use this range adaptor to create a `common_view`. It guarantees that the type of the begin iterator and the type of the end sentinel are the same.
213
213
214
214
### Example: `common`
215
215
@@ -396,7 +396,7 @@ Create a view that contains the elements of a range that remain after the leadin
@@ -722,7 +722,7 @@ The type of the elements to extract from the stream.
722
722
A [`basic_istream_view`](basic-istream-view-class.md).
723
723
724
724
725
-
This range adapter is equivalent to `ranges::basic_istream_view<Val, typename U::char_type, typename U::traits_type>(str)`, where `U` is the type of `str`.
725
+
This range adaptor is equivalent to `ranges::basic_istream_view<Val, typename U::char_type, typename U::traits_type>(str)`, where `U` is the type of `str`.
726
726
727
727
### Example: `istream`
728
728
@@ -755,7 +755,7 @@ Create a view that combines all the elements of multiple ranges into a single vi
Copy file name to clipboardExpand all lines: docs/standard-library/ranges.md
+8-8Lines changed: 8 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -50,9 +50,9 @@ The result, `output`, is itself a kind of range called a *view*.
50
50
51
51
A view is a lightweight range. View operations--such as default construction, move construction/assignment, copy construction/assignment (if present), destruction, begin, and end--all happen in constant time regardless of the number of elements in the view.
52
52
53
-
Views are created by range adapters, which are discussed in the following section. For more information about the classes that implement various views, see [View classes](view-classes.md).
53
+
Views are created by range adaptors, which are discussed in the following section. For more information about the classes that implement various views, see [View classes](view-classes.md).
54
54
55
-
How the elements in the view appear depends on the range adapter that you use to create the view. In the previous example, a range adapter takes a range and returns a view of the elements divisible by three. The underlying range is unchanged.
55
+
How the elements in the view appear depends on the range adaptor that you use to create the view. In the previous example, a range adaptor takes a range and returns a view of the elements divisible by three. The underlying range is unchanged.
56
56
57
57
Views are composable, which is powerful. In the previous example, the view of vector elements that are divisible by three is combined with the view that squares those elements.
58
58
@@ -81,15 +81,15 @@ int main()
81
81
}
82
82
```
83
83
84
-
## Range adapters
84
+
## Range adaptors
85
85
86
-
Range adapters take a range and produce a view. Range adapters produce lazily evaluated views. That is, you don't incur the cost of transforming every element in the range to produce the view. You only pay the cost to process an element in the view when you access that element.
86
+
Range adaptors take a range and produce a view. Range adaptors produce lazily evaluated views. That is, you don't incur the cost of transforming every element in the range to produce the view. You only pay the cost to process an element in the view when you access that element.
87
87
88
-
In the previous example, the `filter` range adapter creates a view named `input` that contains the elements that are divisible by three. The `transform` range adapter takes the view of elements divisible by three and creates a view of those elements squared.
88
+
In the previous example, the `filter` range adaptor creates a view named `input` that contains the elements that are divisible by three. The `transform` range adaptor takes the view of elements divisible by three and creates a view of those elements squared.
89
89
90
-
Range adapters can be chained together (composed), which is the heart of the power and flexibility of ranges. Composing range adapters allows you to overcome the problem that the previous STL algorithms aren't easily composable.
90
+
Range adaptors can be chained together (composed), which is the heart of the power and flexibility of ranges. Composing range adaptors allows you to overcome the problem that the previous STL algorithms aren't easily composable.
91
91
92
-
For more information about creating views, see [Range adapters](range-adaptors.md).
92
+
For more information about creating views, see [Range adaptors](range-adaptors.md).
93
93
94
94
## Range algorithms
95
95
@@ -134,5 +134,5 @@ The range concepts mirror the hierarchy of iterator categories. The following ta
0 commit comments