tmp/tmpp5iw6hxb/{from.md → to.md}
RENAMED
|
@@ -31,30 +31,38 @@ constexpr bool reservable-container = // exposition only
|
|
| 31 |
{ c.capacity() } -> same_as<decltype(n)>;
|
| 32 |
{ c.max_size() } -> same_as<decltype(n)>;
|
| 33 |
};
|
| 34 |
```
|
| 35 |
|
| 36 |
-
Let *`container-
|
| 37 |
|
| 38 |
``` cpp
|
| 39 |
template<class Container, class Ref>
|
| 40 |
-
constexpr bool container-
|
| 41 |
requires(Container& c, Ref&& ref) {
|
| 42 |
-
requires (requires { c.
|
|
|
|
|
|
|
| 43 |
requires { c.insert(c.end(), std::forward<Ref>(ref)); });
|
| 44 |
};
|
| 45 |
```
|
| 46 |
|
| 47 |
-
Let *`container-
|
| 48 |
|
| 49 |
``` cpp
|
| 50 |
-
template<class
|
| 51 |
-
constexpr auto container-
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
else
|
| 55 |
-
|
|
|
|
| 56 |
}
|
| 57 |
```
|
| 58 |
|
| 59 |
#### `ranges::to` <a id="range.utility.conv.to">[[range.utility.conv.to]]</a>
|
| 60 |
|
|
@@ -90,21 +98,22 @@ the following manner:
|
|
| 90 |
``` cpp
|
| 91 |
C(ranges::begin(r), ranges::end(r), std::forward<Args>(args)...)
|
| 92 |
```
|
| 93 |
- Otherwise, if
|
| 94 |
- `constructible_from<C, Args...>` is `true`, and
|
| 95 |
-
- *`container-
|
| 96 |
|
| 97 |
``` cpp
|
| 98 |
C c(std::forward<Args>(args)...);
|
| 99 |
-
if constexpr (
|
| 100 |
-
c.reserve(static_cast<range_size_t<C>>(ranges::
|
| 101 |
-
ranges::
|
| 102 |
```
|
|
|
|
| 103 |
- Otherwise, if `input_range<range_reference_t<R>>` is `true`:
|
| 104 |
``` cpp
|
| 105 |
-
to<C>(r | views::transform([](auto&& elem) {
|
| 106 |
return to<range_value_t<C>>(std::forward<decltype(elem)>(elem));
|
| 107 |
}), std::forward<Args>(args)...);
|
| 108 |
```
|
| 109 |
- Otherwise, the program is ill-formed.
|
| 110 |
|
|
|
|
| 31 |
{ c.capacity() } -> same_as<decltype(n)>;
|
| 32 |
{ c.max_size() } -> same_as<decltype(n)>;
|
| 33 |
};
|
| 34 |
```
|
| 35 |
|
| 36 |
+
Let *`container-appendable`* be defined as follows:
|
| 37 |
|
| 38 |
``` cpp
|
| 39 |
template<class Container, class Ref>
|
| 40 |
+
constexpr bool container-appendable = // exposition only
|
| 41 |
requires(Container& c, Ref&& ref) {
|
| 42 |
+
requires (requires { c.emplace_back(std::forward<Ref>(ref)); } ||
|
| 43 |
+
requires { c.push_back(std::forward<Ref>(ref)); } ||
|
| 44 |
+
requires { c.emplace(c.end(), std::forward<Ref>(ref)); } ||
|
| 45 |
requires { c.insert(c.end(), std::forward<Ref>(ref)); });
|
| 46 |
};
|
| 47 |
```
|
| 48 |
|
| 49 |
+
Let *`container-append`* be defined as follows:
|
| 50 |
|
| 51 |
``` cpp
|
| 52 |
+
template<class Container>
|
| 53 |
+
constexpr auto container-append(Container& c) { // exposition only
|
| 54 |
+
return [&c]<class Ref>(Ref&& ref) {
|
| 55 |
+
if constexpr (requires { c.emplace_back(declval<Ref>()); })
|
| 56 |
+
c.emplace_back(std::forward<Ref>(ref));
|
| 57 |
+
else if constexpr (requires { c.push_back(declval<Ref>()); })
|
| 58 |
+
c.push_back(std::forward<Ref>(ref));
|
| 59 |
+
else if constexpr (requires { c.emplace(c.end(), declval<Ref>()); })
|
| 60 |
+
c.emplace(c.end(), std::forward<Ref>(ref));
|
| 61 |
else
|
| 62 |
+
c.insert(c.end(), std::forward<Ref>(ref));
|
| 63 |
+
};
|
| 64 |
}
|
| 65 |
```
|
| 66 |
|
| 67 |
#### `ranges::to` <a id="range.utility.conv.to">[[range.utility.conv.to]]</a>
|
| 68 |
|
|
|
|
| 98 |
``` cpp
|
| 99 |
C(ranges::begin(r), ranges::end(r), std::forward<Args>(args)...)
|
| 100 |
```
|
| 101 |
- Otherwise, if
|
| 102 |
- `constructible_from<C, Args...>` is `true`, and
|
| 103 |
+
- *`container-appendable`*`<C, range_reference_t<R>>` is `true`:
|
| 104 |
|
| 105 |
``` cpp
|
| 106 |
C c(std::forward<Args>(args)...);
|
| 107 |
+
if constexpr (approximately_sized_range<R> && reservable-container<C>)
|
| 108 |
+
c.reserve(static_cast<range_size_t<C>>(ranges::reserve_hint(r)));
|
| 109 |
+
ranges::for_each(r, container-append(c));
|
| 110 |
```
|
| 111 |
+
- Otherwise, the program is ill-formed.
|
| 112 |
- Otherwise, if `input_range<range_reference_t<R>>` is `true`:
|
| 113 |
``` cpp
|
| 114 |
+
to<C>(ref_view(r) | views::transform([](auto&& elem) {
|
| 115 |
return to<range_value_t<C>>(std::forward<decltype(elem)>(elem));
|
| 116 |
}), std::forward<Args>(args)...);
|
| 117 |
```
|
| 118 |
- Otherwise, the program is ill-formed.
|
| 119 |
|