tmp/tmp5dklagt3/{from.md → to.md}
RENAMED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#### General <a id="range.utility.conv.general">[[range.utility.conv.general]]</a>
|
| 2 |
+
|
| 3 |
+
The range conversion functions construct an object (usually a container)
|
| 4 |
+
from a range, by using a constructor taking a range, a `from_range_t`
|
| 5 |
+
tagged constructor, or a constructor taking a pair of iterators, or by
|
| 6 |
+
inserting each element of the range into the default-constructed object.
|
| 7 |
+
|
| 8 |
+
`ranges::to` is applied recursively, allowing the conversion of a range
|
| 9 |
+
of ranges.
|
| 10 |
+
|
| 11 |
+
[*Example 1*:
|
| 12 |
+
|
| 13 |
+
``` cpp
|
| 14 |
+
string_view str = "the quick brown fox";
|
| 15 |
+
auto words = views::split(str, ' ') | to<vector<string>>();
|
| 16 |
+
// words is vector<string>{"the", "quick", "brown", "fox"}
|
| 17 |
+
```
|
| 18 |
+
|
| 19 |
+
— *end example*]
|
| 20 |
+
|
| 21 |
+
Let *`reservable-container`* be defined as follows:
|
| 22 |
+
|
| 23 |
+
``` cpp
|
| 24 |
+
template<class Container>
|
| 25 |
+
constexpr bool reservable-container = // exposition only
|
| 26 |
+
sized_range<Container> &&
|
| 27 |
+
requires(Container& c, range_size_t<Container> n) {
|
| 28 |
+
c.reserve(n);
|
| 29 |
+
{ c.capacity() } -> same_as<decltype(n)>;
|
| 30 |
+
{ c.max_size() } -> same_as<decltype(n)>;
|
| 31 |
+
};
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
Let *`container-insertable`* be defined as follows:
|
| 35 |
+
|
| 36 |
+
``` cpp
|
| 37 |
+
template<class Container, class Ref>
|
| 38 |
+
constexpr bool container-insertable = // exposition only
|
| 39 |
+
requires(Container& c, Ref&& ref) {
|
| 40 |
+
requires (requires { c.push_back(std::forward<Ref>(ref)); } ||
|
| 41 |
+
requires { c.insert(c.end(), std::forward<Ref>(ref)); });
|
| 42 |
+
};
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
Let *`container-inserter`* be defined as follows:
|
| 46 |
+
|
| 47 |
+
``` cpp
|
| 48 |
+
template<class Ref, class Container>
|
| 49 |
+
constexpr auto container-inserter(Container& c) { // exposition only
|
| 50 |
+
if constexpr (requires { c.push_back(declval<Ref>()); })
|
| 51 |
+
return back_inserter(c);
|
| 52 |
+
else
|
| 53 |
+
return inserter(c, c.end());
|
| 54 |
+
}
|
| 55 |
+
```
|
| 56 |
+
|