tmp/tmpi6mkxmvm/{from.md → to.md}
RENAMED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### General <a id="range.adaptors.general">[[range.adaptors.general]]</a>
|
| 2 |
+
|
| 3 |
+
Subclause [[range.adaptors]] defines *range adaptors*, which are
|
| 4 |
+
utilities that transform a range into a view with custom behaviors.
|
| 5 |
+
These adaptors can be chained to create pipelines of range
|
| 6 |
+
transformations that evaluate lazily as the resulting view is iterated.
|
| 7 |
+
|
| 8 |
+
Range adaptors are declared in namespace `std::ranges::views`.
|
| 9 |
+
|
| 10 |
+
The bitwise operator is overloaded for the purpose of creating adaptor
|
| 11 |
+
chain pipelines. The adaptors also support function call syntax with
|
| 12 |
+
equivalent semantics.
|
| 13 |
+
|
| 14 |
+
[*Example 1*:
|
| 15 |
+
|
| 16 |
+
``` cpp
|
| 17 |
+
vector<int> ints{0,1,2,3,4,5};
|
| 18 |
+
auto even = [](int i) { return 0 == i % 2; };
|
| 19 |
+
auto square = [](int i) { return i * i; };
|
| 20 |
+
for (int i : ints | views::filter(even) | views::transform(square)) {
|
| 21 |
+
cout << i << ' '; // prints 0 4 16
|
| 22 |
+
}
|
| 23 |
+
assert(ranges::equal(ints | views::filter(even), views::filter(ints, even)));
|
| 24 |
+
```
|
| 25 |
+
|
| 26 |
+
— *end example*]
|
| 27 |
+
|