tmp/tmp43ohu_jl/{from.md → to.md}
RENAMED
|
@@ -1,11 +1,11 @@
|
|
| 1 |
### Merge <a id="alg.merge">[[alg.merge]]</a>
|
| 2 |
|
| 3 |
``` cpp
|
| 4 |
template<class InputIterator1, class InputIterator2,
|
| 5 |
class OutputIterator>
|
| 6 |
-
OutputIterator
|
| 7 |
merge(InputIterator1 first1, InputIterator1 last1,
|
| 8 |
InputIterator2 first2, InputIterator2 last2,
|
| 9 |
OutputIterator result);
|
| 10 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 11 |
class ForwardIterator>
|
|
@@ -15,43 +15,67 @@ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
|
| 15 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 16 |
ForwardIterator result);
|
| 17 |
|
| 18 |
template<class InputIterator1, class InputIterator2,
|
| 19 |
class OutputIterator, class Compare>
|
| 20 |
-
OutputIterator
|
| 21 |
merge(InputIterator1 first1, InputIterator1 last1,
|
| 22 |
InputIterator2 first2, InputIterator2 last2,
|
| 23 |
OutputIterator result, Compare comp);
|
| 24 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 25 |
class ForwardIterator, class Compare>
|
| 26 |
ForwardIterator
|
| 27 |
merge(ExecutionPolicy&& exec,
|
| 28 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 29 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 30 |
ForwardIterator result, Compare comp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
```
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
|
| 37 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
`last1`) and \[`first2`, `last2`) into the range \[`result`,
|
| 39 |
-
`result_last`), where `result_last` is
|
| 40 |
-
`
|
| 41 |
-
|
| 42 |
-
`
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
*Returns:*
|
| 45 |
|
| 46 |
-
|
|
|
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
| 50 |
- For the overloads with an `ExecutionPolicy`, 𝑂(N) comparisons.
|
| 51 |
|
| 52 |
-
*Remarks:* Stable
|
| 53 |
|
| 54 |
``` cpp
|
| 55 |
template<class BidirectionalIterator>
|
| 56 |
void inplace_merge(BidirectionalIterator first,
|
| 57 |
BidirectionalIterator middle,
|
|
@@ -69,32 +93,52 @@ template<class BidirectionalIterator, class Compare>
|
|
| 69 |
template<class ExecutionPolicy, class BidirectionalIterator, class Compare>
|
| 70 |
void inplace_merge(ExecutionPolicy&& exec,
|
| 71 |
BidirectionalIterator first,
|
| 72 |
BidirectionalIterator middle,
|
| 73 |
BidirectionalIterator last, Compare comp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
```
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
`
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
|
|
|
|
|
|
| 83 |
|
| 84 |
*Effects:* Merges two sorted consecutive ranges \[`first`, `middle`) and
|
| 85 |
\[`middle`, `last`), putting the result of the merge into the range
|
| 86 |
-
\[`first`, `last`). The resulting range
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
|
| 91 |
*Complexity:* Let N = `last - first`:
|
| 92 |
|
| 93 |
-
- For the overloads with no `ExecutionPolicy`, if enough additional
|
| 94 |
memory is available, exactly N - 1 comparisons.
|
| 95 |
-
-
|
| 96 |
-
available, 𝑂(N log N) comparisons.
|
| 97 |
-
- For the overloads with an `ExecutionPolicy`, 𝑂(N log N) comparisons.
|
| 98 |
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
|
|
|
| 1 |
### Merge <a id="alg.merge">[[alg.merge]]</a>
|
| 2 |
|
| 3 |
``` cpp
|
| 4 |
template<class InputIterator1, class InputIterator2,
|
| 5 |
class OutputIterator>
|
| 6 |
+
constexpr OutputIterator
|
| 7 |
merge(InputIterator1 first1, InputIterator1 last1,
|
| 8 |
InputIterator2 first2, InputIterator2 last2,
|
| 9 |
OutputIterator result);
|
| 10 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 11 |
class ForwardIterator>
|
|
|
|
| 15 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 16 |
ForwardIterator result);
|
| 17 |
|
| 18 |
template<class InputIterator1, class InputIterator2,
|
| 19 |
class OutputIterator, class Compare>
|
| 20 |
+
constexpr OutputIterator
|
| 21 |
merge(InputIterator1 first1, InputIterator1 last1,
|
| 22 |
InputIterator2 first2, InputIterator2 last2,
|
| 23 |
OutputIterator result, Compare comp);
|
| 24 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 25 |
class ForwardIterator, class Compare>
|
| 26 |
ForwardIterator
|
| 27 |
merge(ExecutionPolicy&& exec,
|
| 28 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 29 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 30 |
ForwardIterator result, Compare comp);
|
| 31 |
+
|
| 32 |
+
template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
|
| 33 |
+
weakly_incrementable O, class Comp = ranges::less, class Proj1 = identity,
|
| 34 |
+
class Proj2 = identity>
|
| 35 |
+
requires mergeable<I1, I2, O, Comp, Proj1, Proj2>
|
| 36 |
+
constexpr ranges::merge_result<I1, I2, O>
|
| 37 |
+
ranges::merge(I1 first1, S1 last1, I2 first2, S2 last2, O result,
|
| 38 |
+
Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 39 |
+
template<input_range R1, input_range R2, weakly_incrementable O, class Comp = ranges::less,
|
| 40 |
+
class Proj1 = identity, class Proj2 = identity>
|
| 41 |
+
requires mergeable<iterator_t<R1>, iterator_t<R2>, O, Comp, Proj1, Proj2>
|
| 42 |
+
constexpr ranges::merge_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>, O>
|
| 43 |
+
ranges::merge(R1&& r1, R2&& r2, O result,
|
| 44 |
+
Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 45 |
```
|
| 46 |
|
| 47 |
+
Let N be `(last1 - first1) + (last2 - first2)`. Let `comp` be `less{}`,
|
| 48 |
+
`proj1` be `identity{}`, and `proj2` be `identity{}`, for the overloads
|
| 49 |
+
with no parameters by those names.
|
| 50 |
|
| 51 |
+
*Preconditions:* The ranges \[`first1`, `last1`) and \[`first2`,
|
| 52 |
+
`last2`) are sorted with respect to `comp` and `proj1` or `proj2`,
|
| 53 |
+
respectively. The resulting range does not overlap with either of the
|
| 54 |
+
original ranges.
|
| 55 |
+
|
| 56 |
+
*Effects:* Copies all the elements of the two ranges \[`first1`,
|
| 57 |
`last1`) and \[`first2`, `last2`) into the range \[`result`,
|
| 58 |
+
`result_last`), where `result_last` is `result + `N. If an element `a`
|
| 59 |
+
precedes `b` in an input range, `a` is copied into the output range
|
| 60 |
+
before `b`. If `e1` is an element of \[`first1`, `last1`) and `e2` of
|
| 61 |
+
\[`first2`, `last2`), `e2` is copied into the output range before `e1`
|
| 62 |
+
if and only if
|
| 63 |
+
`bool(invoke(comp, invoke(proj2, e2), invoke(proj1, e1)))` is `true`.
|
| 64 |
|
| 65 |
+
*Returns:*
|
| 66 |
|
| 67 |
+
- `result_last` for the overloads in namespace `std`.
|
| 68 |
+
- `{last1, last2, result_last}` for the overloads in namespace `ranges`.
|
| 69 |
|
| 70 |
+
*Complexity:*
|
| 71 |
+
|
| 72 |
+
- For the overloads with no `ExecutionPolicy`, at most N - 1 comparisons
|
| 73 |
+
and applications of each projection.
|
| 74 |
- For the overloads with an `ExecutionPolicy`, 𝑂(N) comparisons.
|
| 75 |
|
| 76 |
+
*Remarks:* Stable [[algorithm.stable]].
|
| 77 |
|
| 78 |
``` cpp
|
| 79 |
template<class BidirectionalIterator>
|
| 80 |
void inplace_merge(BidirectionalIterator first,
|
| 81 |
BidirectionalIterator middle,
|
|
|
|
| 93 |
template<class ExecutionPolicy, class BidirectionalIterator, class Compare>
|
| 94 |
void inplace_merge(ExecutionPolicy&& exec,
|
| 95 |
BidirectionalIterator first,
|
| 96 |
BidirectionalIterator middle,
|
| 97 |
BidirectionalIterator last, Compare comp);
|
| 98 |
+
|
| 99 |
+
template<bidirectional_iterator I, sentinel_for<I> S, class Comp = ranges::less,
|
| 100 |
+
class Proj = identity>
|
| 101 |
+
requires sortable<I, Comp, Proj>
|
| 102 |
+
I ranges::inplace_merge(I first, I middle, S last, Comp comp = {}, Proj proj = {});
|
| 103 |
```
|
| 104 |
|
| 105 |
+
Let `comp` be `less{}` and `proj` be `identity{}` for the overloads with
|
| 106 |
+
no parameters by those names.
|
| 107 |
+
|
| 108 |
+
*Preconditions:* \[`first`, `middle`) and \[`middle`, `last`) are valid
|
| 109 |
+
ranges sorted with respect to `comp` and `proj`. For the overloads in
|
| 110 |
+
namespace `std`, `BidirectionalIterator` meets the *Cpp17ValueSwappable*
|
| 111 |
+
requirements [[swappable.requirements]] and the type of `*first` meets
|
| 112 |
+
the *Cpp17MoveConstructible* ([[cpp17.moveconstructible]]) and
|
| 113 |
+
*Cpp17MoveAssignable* ([[cpp17.moveassignable]]) requirements.
|
| 114 |
|
| 115 |
*Effects:* Merges two sorted consecutive ranges \[`first`, `middle`) and
|
| 116 |
\[`middle`, `last`), putting the result of the merge into the range
|
| 117 |
+
\[`first`, `last`). The resulting range is sorted with respect to `comp`
|
| 118 |
+
and `proj`.
|
| 119 |
+
|
| 120 |
+
*Returns:* `last` for the overload in namespace `ranges`.
|
| 121 |
|
| 122 |
*Complexity:* Let N = `last - first`:
|
| 123 |
|
| 124 |
+
- For the overloads with no `ExecutionPolicy`, and if enough additional
|
| 125 |
memory is available, exactly N - 1 comparisons.
|
| 126 |
+
- Otherwise, 𝑂(N log N) comparisons.
|
|
|
|
|
|
|
| 127 |
|
| 128 |
+
In either case, twice as many projections as comparisons.
|
| 129 |
+
|
| 130 |
+
*Remarks:* Stable [[algorithm.stable]].
|
| 131 |
+
|
| 132 |
+
``` cpp
|
| 133 |
+
template<bidirectional_range R, class Comp = ranges::less, class Proj = identity>
|
| 134 |
+
requires sortable<iterator_t<R>, Comp, Proj>
|
| 135 |
+
borrowed_iterator_t<R>
|
| 136 |
+
ranges::inplace_merge(R&& r, iterator_t<R> middle, Comp comp = {}, Proj proj = {});
|
| 137 |
+
```
|
| 138 |
+
|
| 139 |
+
*Effects:* Equivalent to:
|
| 140 |
+
|
| 141 |
+
``` cpp
|
| 142 |
+
return ranges::inplace_merge(ranges::begin(r), middle, ranges::end(r), comp, proj);
|
| 143 |
+
```
|
| 144 |
|