tmp/tmp6bzrxbgb/{from.md → to.md}
RENAMED
|
@@ -1,10 +1,10 @@
|
|
| 1 |
#### Overview <a id="range.elements.overview">[[range.elements.overview]]</a>
|
| 2 |
|
| 3 |
-
`elements_view` takes a
|
| 4 |
-
produces a
|
| 5 |
-
|
| 6 |
|
| 7 |
The name `views::elements<N>` denotes a range adaptor object
|
| 8 |
[[range.adaptor.object]]. Given a subexpression `E` and constant
|
| 9 |
expression `N`, the expression `views::elements<N>(E)` is
|
| 10 |
expression-equivalent to
|
|
@@ -12,11 +12,11 @@ expression-equivalent to
|
|
| 12 |
|
| 13 |
[*Example 1*:
|
| 14 |
|
| 15 |
``` cpp
|
| 16 |
auto historical_figures = map{
|
| 17 |
-
{"Lovelace"sv, 1815},
|
| 18 |
{"Turing"sv, 1912},
|
| 19 |
{"Babbage"sv, 1791},
|
| 20 |
{"Hamilton"sv, 1936}
|
| 21 |
};
|
| 22 |
|
|
@@ -31,31 +31,31 @@ for (auto&& born : birth_years) {
|
|
| 31 |
}
|
| 32 |
```
|
| 33 |
|
| 34 |
— *end example*]
|
| 35 |
|
| 36 |
-
`keys_view` is an alias for `elements_view<
|
| 37 |
-
|
| 38 |
|
| 39 |
[*Example 2*:
|
| 40 |
|
| 41 |
``` cpp
|
| 42 |
-
auto names =
|
| 43 |
for (auto&& name : names) {
|
| 44 |
cout << name << ' '; // prints Babbage Hamilton Lovelace Turing
|
| 45 |
}
|
| 46 |
```
|
| 47 |
|
| 48 |
— *end example*]
|
| 49 |
|
| 50 |
-
`values_view` is an alias for `elements_view<
|
| 51 |
-
|
| 52 |
|
| 53 |
[*Example 3*:
|
| 54 |
|
| 55 |
``` cpp
|
| 56 |
auto is_even = [](const auto x) { return x % 2 == 0; };
|
| 57 |
-
cout << ranges::count_if(
|
| 58 |
```
|
| 59 |
|
| 60 |
— *end example*]
|
| 61 |
|
|
|
|
| 1 |
#### Overview <a id="range.elements.overview">[[range.elements.overview]]</a>
|
| 2 |
|
| 3 |
+
`elements_view` takes a view of tuple-like values and a `size_t`, and
|
| 4 |
+
produces a view with a value-type of the Nᵗʰ element of the adapted
|
| 5 |
+
view’s value-type.
|
| 6 |
|
| 7 |
The name `views::elements<N>` denotes a range adaptor object
|
| 8 |
[[range.adaptor.object]]. Given a subexpression `E` and constant
|
| 9 |
expression `N`, the expression `views::elements<N>(E)` is
|
| 10 |
expression-equivalent to
|
|
|
|
| 12 |
|
| 13 |
[*Example 1*:
|
| 14 |
|
| 15 |
``` cpp
|
| 16 |
auto historical_figures = map{
|
| 17 |
+
pair{"Lovelace"sv, 1815},
|
| 18 |
{"Turing"sv, 1912},
|
| 19 |
{"Babbage"sv, 1791},
|
| 20 |
{"Hamilton"sv, 1936}
|
| 21 |
};
|
| 22 |
|
|
|
|
| 31 |
}
|
| 32 |
```
|
| 33 |
|
| 34 |
— *end example*]
|
| 35 |
|
| 36 |
+
`keys_view` is an alias for `elements_view<R, 0>`, and is useful for
|
| 37 |
+
extracting keys from associative containers.
|
| 38 |
|
| 39 |
[*Example 2*:
|
| 40 |
|
| 41 |
``` cpp
|
| 42 |
+
auto names = historical_figures | views::keys;
|
| 43 |
for (auto&& name : names) {
|
| 44 |
cout << name << ' '; // prints Babbage Hamilton Lovelace Turing
|
| 45 |
}
|
| 46 |
```
|
| 47 |
|
| 48 |
— *end example*]
|
| 49 |
|
| 50 |
+
`values_view` is an alias for `elements_view<R, 1>`, and is useful for
|
| 51 |
+
extracting values from associative containers.
|
| 52 |
|
| 53 |
[*Example 3*:
|
| 54 |
|
| 55 |
``` cpp
|
| 56 |
auto is_even = [](const auto x) { return x % 2 == 0; };
|
| 57 |
+
cout << ranges::count_if(historical_figures | views::values, is_even); // prints 2
|
| 58 |
```
|
| 59 |
|
| 60 |
— *end example*]
|
| 61 |
|