tmp/tmpq15mlcox/{from.md → to.md}
RENAMED
|
@@ -65,14 +65,14 @@ template<input_iterator I, weakly_incrementable O>
|
|
| 65 |
```
|
| 66 |
|
| 67 |
Let N be max(0, `n`).
|
| 68 |
|
| 69 |
*Mandates:* The type `Size` is convertible to an integral
|
| 70 |
-
type
|
| 71 |
|
| 72 |
*Effects:* For each non-negative integer i < N, performs
|
| 73 |
-
`*(result + i) = *(first + i)`.
|
| 74 |
|
| 75 |
*Returns:*
|
| 76 |
|
| 77 |
- `result + `N for the overloads in namespace `std`.
|
| 78 |
- `{first + `N`, result + `N`}` for the overload in namespace `ranges`.
|
|
@@ -111,11 +111,11 @@ and N be the number of iterators `i` in the range \[`first`, `last`) for
|
|
| 111 |
which the condition E holds.
|
| 112 |
|
| 113 |
*Preconditions:* The ranges \[`first`, `last`) and \[`result`,
|
| 114 |
`result + (last - first)`) do not overlap.
|
| 115 |
|
| 116 |
-
[*Note 1*: For the overload with an `ExecutionPolicy`, there
|
| 117 |
performance cost if `iterator_traits<ForwardIterator1>::value_type` is
|
| 118 |
not *Cpp17MoveConstructible*
|
| 119 |
([[cpp17.moveconstructible]]). — *end note*]
|
| 120 |
|
| 121 |
*Effects:* Copies all of the elements referred to by the iterator `i` in
|
|
@@ -152,11 +152,13 @@ Let N be `last - first`.
|
|
| 152 |
|
| 153 |
*Preconditions:* `result` is not in the range (`first`, `last`).
|
| 154 |
|
| 155 |
*Effects:* Copies elements in the range \[`first`, `last`) into the
|
| 156 |
range \[`result - `N, `result`) starting from `last - 1` and proceeding
|
| 157 |
-
to `first`.
|
|
|
|
|
|
|
| 158 |
`*(result - `n`) = *(last - `n`)`.
|
| 159 |
|
| 160 |
*Returns:*
|
| 161 |
|
| 162 |
- `result - `N for the overload in namespace `std`.
|
|
@@ -249,12 +251,13 @@ Let N be `last - first`.
|
|
| 249 |
|
| 250 |
*Preconditions:* `result` is not in the range (`first`, `last`).
|
| 251 |
|
| 252 |
*Effects:* Moves elements in the range \[`first`, `last`) into the range
|
| 253 |
\[`result - `N, `result`) starting from `last - 1` and proceeding to
|
| 254 |
-
`first`.
|
| 255 |
-
|
|
|
|
| 256 |
|
| 257 |
*Returns:*
|
| 258 |
|
| 259 |
- `result - `N for the overload in namespace `std`.
|
| 260 |
- `{last, result - `N`}` for the overloads in namespace `ranges`.
|
|
@@ -572,11 +575,10 @@ template<class OutputIterator, class Size, class T>
|
|
| 572 |
constexpr OutputIterator fill_n(OutputIterator first, Size n, const T& value);
|
| 573 |
template<class ExecutionPolicy, class ForwardIterator, class Size, class T>
|
| 574 |
ForwardIterator fill_n(ExecutionPolicy&& exec,
|
| 575 |
ForwardIterator first, Size n, const T& value);
|
| 576 |
|
| 577 |
-
|
| 578 |
template<class T, output_iterator<const T&> O, sentinel_for<O> S>
|
| 579 |
constexpr O ranges::fill(O first, S last, const T& value);
|
| 580 |
template<class T, output_range<const T&> R>
|
| 581 |
constexpr borrowed_iterator_t<R> ranges::fill(R&& r, const T& value);
|
| 582 |
template<class T, output_iterator<const T&> O>
|
|
@@ -586,12 +588,12 @@ template<class T, output_iterator<const T&> O>
|
|
| 586 |
Let N be max(0, `n`) for the `fill_n` algorithms, and `last - first` for
|
| 587 |
the `fill` algorithms.
|
| 588 |
|
| 589 |
*Mandates:* The expression `value` is
|
| 590 |
writable [[iterator.requirements.general]] to the output iterator. The
|
| 591 |
-
type `Size` is convertible to an integral
|
| 592 |
-
[[class.conv]]
|
| 593 |
|
| 594 |
*Effects:* Assigns `value` through all the iterators in the range
|
| 595 |
\[`first`, `first + `N).
|
| 596 |
|
| 597 |
*Returns:* `first + `N.
|
|
@@ -628,11 +630,11 @@ template<input_or_output_iterator O, copy_constructible F>
|
|
| 628 |
|
| 629 |
Let N be max(0, `n`) for the `generate_n` algorithms, and `last - first`
|
| 630 |
for the `generate` algorithms.
|
| 631 |
|
| 632 |
*Mandates:* `Size` is convertible to an integral
|
| 633 |
-
type
|
| 634 |
|
| 635 |
*Effects:* Assigns the result of successive evaluations of `gen()`
|
| 636 |
through each iterator in the range \[`first`, `first + `N).
|
| 637 |
|
| 638 |
*Returns:* `first + `N.
|
|
@@ -693,15 +695,15 @@ the range \[`first`, `last`) for which E holds.
|
|
| 693 |
*Returns:* Let j be the end of the resulting range. Returns:
|
| 694 |
|
| 695 |
- j for the overloads in namespace `std`.
|
| 696 |
- `{`j`, last}` for the overloads in namespace `ranges`.
|
| 697 |
|
| 698 |
-
*Remarks:* Stable [[algorithm.stable]].
|
| 699 |
-
|
| 700 |
*Complexity:* Exactly `last - first` applications of the corresponding
|
| 701 |
predicate and any projection.
|
| 702 |
|
|
|
|
|
|
|
| 703 |
[*Note 1*: Each element in the range \[`ret`, `last`), where `ret` is
|
| 704 |
the returned value, has a valid but unspecified state, because the
|
| 705 |
algorithms can eliminate elements by moving from elements that were
|
| 706 |
originally in that range. — *end note*]
|
| 707 |
|
|
@@ -765,14 +767,14 @@ Let N be the number of elements in \[`first`, `last`) for which E is
|
|
| 765 |
`result`.
|
| 766 |
|
| 767 |
*Preconditions:* The ranges \[`first`, `last`) and \[`result`,
|
| 768 |
`result + (last - first)`) do not overlap.
|
| 769 |
|
| 770 |
-
[*Note 2*: For the overloads with an `ExecutionPolicy`, there
|
| 771 |
-
performance cost if `iterator_traits<ForwardIterator1>::value_type`
|
| 772 |
-
not meet the *Cpp17MoveConstructible*
|
| 773 |
-
requirements. — *end note*]
|
| 774 |
|
| 775 |
*Effects:* Copies all the elements referred to by the iterator `i` in
|
| 776 |
the range \[`first`, `last`) for which E is `false`.
|
| 777 |
|
| 778 |
*Returns:*
|
|
@@ -817,11 +819,11 @@ and let E be
|
|
| 817 |
|
| 818 |
- `bool(pred(*(i - 1), *i))` for the overloads in namespace `std`;
|
| 819 |
- `bool(invoke(comp, invoke(proj, *(i - 1)), invoke(proj, *i)))` for the
|
| 820 |
overloads in namespace `ranges`.
|
| 821 |
|
| 822 |
-
*Preconditions:* For the overloads in
|
| 823 |
equivalence relation and the type of `*first` meets the
|
| 824 |
*Cpp17MoveAssignable* requirements ([[cpp17.moveassignable]]).
|
| 825 |
|
| 826 |
*Effects:* For a nonempty range, eliminates all but the first element
|
| 827 |
from every consecutive group of equivalent elements referred to by the
|
|
@@ -892,19 +894,19 @@ parameter `pred`, and let E be
|
|
| 892 |
- The ranges \[`first`, `last`) and \[`result`, `result+(last-first)`)
|
| 893 |
do not overlap.
|
| 894 |
- For the overloads in namespace `std`:
|
| 895 |
- The comparison function is an equivalence relation.
|
| 896 |
- For the overloads with no `ExecutionPolicy`, let `T` be the value
|
| 897 |
-
type of `InputIterator`. If `InputIterator`
|
| 898 |
-
|
| 899 |
-
requirements for `T`. Otherwise, if `OutputIterator`
|
| 900 |
-
*Cpp17ForwardIterator* requirements and its value type is
|
| 901 |
-
as `T`, then `T` meets the *Cpp17CopyAssignable*
|
| 902 |
([[cpp17.copyassignable]]) requirements. Otherwise, `T` meets both
|
| 903 |
the *Cpp17CopyConstructible* ([[cpp17.copyconstructible]]) and
|
| 904 |
*Cpp17CopyAssignable* requirements. \[*Note 1*: For the overloads
|
| 905 |
-
with an `ExecutionPolicy`, there
|
| 906 |
value type of `ForwardIterator1` does not meet both the
|
| 907 |
*Cpp17CopyConstructible* and *Cpp17CopyAssignable*
|
| 908 |
requirements. — *end note*]
|
| 909 |
|
| 910 |
*Effects:* Copies only the first element from every consecutive group of
|
|
@@ -1076,11 +1078,11 @@ template<forward_range R, weakly_incrementable O>
|
|
| 1076 |
```
|
| 1077 |
|
| 1078 |
*Effects:* Equivalent to:
|
| 1079 |
|
| 1080 |
``` cpp
|
| 1081 |
-
return ranges::rotate_copy(ranges::begin(r), middle, ranges::end(r), result);
|
| 1082 |
```
|
| 1083 |
|
| 1084 |
### Sample <a id="alg.random.sample">[[alg.random.sample]]</a>
|
| 1085 |
|
| 1086 |
``` cpp
|
|
@@ -1113,11 +1115,11 @@ overload in namespace `std`:
|
|
| 1113 |
requirements [[input.iterators]].
|
| 1114 |
- `SampleIterator` meets the *Cpp17OutputIterator*
|
| 1115 |
requirements [[output.iterators]].
|
| 1116 |
- `SampleIterator` meets the *Cpp17RandomAccessIterator*
|
| 1117 |
requirements [[random.access.iterators]] unless `PopulationIterator`
|
| 1118 |
-
|
| 1119 |
- `remove_reference_t<UniformRandomBitGenerator>` meets the requirements
|
| 1120 |
of a uniform random bit generator type [[rand.req.urng]].
|
| 1121 |
|
| 1122 |
*Effects:* Copies min(`last - first`, `n`) elements (the *sample*) from
|
| 1123 |
\[`first`, `last`) (the *population*) to `out` such that each possible
|
|
@@ -1131,13 +1133,13 @@ sampling* and *reservoir sampling*. — *end note*]
|
|
| 1131 |
*Complexity:* 𝑂(`last - first`).
|
| 1132 |
|
| 1133 |
*Remarks:*
|
| 1134 |
|
| 1135 |
- For the overload in namespace `std`, stable if and only if
|
| 1136 |
-
`PopulationIterator`
|
| 1137 |
-
|
| 1138 |
-
`
|
| 1139 |
- To the extent that the implementation of this function makes use of
|
| 1140 |
random numbers, the object `g` serves as the implementation’s source
|
| 1141 |
of randomness.
|
| 1142 |
|
| 1143 |
### Shuffle <a id="alg.random.shuffle">[[alg.random.shuffle]]</a>
|
|
@@ -1186,23 +1188,34 @@ template<class ForwardIterator>
|
|
| 1186 |
typename iterator_traits<ForwardIterator>::difference_type n);
|
| 1187 |
template<class ExecutionPolicy, class ForwardIterator>
|
| 1188 |
ForwardIterator
|
| 1189 |
shift_left(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
|
| 1190 |
typename iterator_traits<ForwardIterator>::difference_type n);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1191 |
```
|
| 1192 |
|
| 1193 |
-
*Preconditions:* `n >= 0` is `true`.
|
| 1194 |
-
*Cpp17MoveAssignable*
|
|
|
|
| 1195 |
|
| 1196 |
*Effects:* If `n == 0` or `n >= last - first`, does nothing. Otherwise,
|
| 1197 |
moves the element from position `first + n + i` into position
|
| 1198 |
-
`first + i` for each non-negative integer `i < (last - first) - n`.
|
| 1199 |
-
the
|
| 1200 |
-
|
|
|
|
| 1201 |
|
| 1202 |
-
*Returns:* `first + (last - first - n)` if
|
| 1203 |
-
`first`.
|
|
|
|
|
|
|
|
|
|
| 1204 |
|
| 1205 |
*Complexity:* At most `(last - first) - n` assignments.
|
| 1206 |
|
| 1207 |
``` cpp
|
| 1208 |
template<class ForwardIterator>
|
|
@@ -1211,23 +1224,39 @@ template<class ForwardIterator>
|
|
| 1211 |
typename iterator_traits<ForwardIterator>::difference_type n);
|
| 1212 |
template<class ExecutionPolicy, class ForwardIterator>
|
| 1213 |
ForwardIterator
|
| 1214 |
shift_right(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
|
| 1215 |
typename iterator_traits<ForwardIterator>::difference_type n);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1216 |
```
|
| 1217 |
|
| 1218 |
-
*Preconditions:* `n >= 0` is `true`.
|
| 1219 |
-
|
|
|
|
| 1220 |
*Cpp17BidirectionalIterator* requirements [[bidirectional.iterators]] or
|
| 1221 |
the *Cpp17ValueSwappable* requirements.
|
| 1222 |
|
| 1223 |
*Effects:* If `n == 0` or `n >= last - first`, does nothing. Otherwise,
|
| 1224 |
moves the element from position `first + i` into position
|
| 1225 |
`first + n + i` for each non-negative integer `i < (last - first) - n`.
|
| 1226 |
-
|
| 1227 |
-
|
| 1228 |
-
from `i = (last - first) - n - 1` and proceeding to `i = 0`.
|
| 1229 |
|
| 1230 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1231 |
|
| 1232 |
*Complexity:* At most `(last - first) - n` assignments or swaps.
|
| 1233 |
|
|
|
|
| 65 |
```
|
| 66 |
|
| 67 |
Let N be max(0, `n`).
|
| 68 |
|
| 69 |
*Mandates:* The type `Size` is convertible to an integral
|
| 70 |
+
type [[conv.integral]], [[class.conv]].
|
| 71 |
|
| 72 |
*Effects:* For each non-negative integer i < N, performs
|
| 73 |
+
`*(result + `i`) = *(first + `i`)`.
|
| 74 |
|
| 75 |
*Returns:*
|
| 76 |
|
| 77 |
- `result + `N for the overloads in namespace `std`.
|
| 78 |
- `{first + `N`, result + `N`}` for the overload in namespace `ranges`.
|
|
|
|
| 111 |
which the condition E holds.
|
| 112 |
|
| 113 |
*Preconditions:* The ranges \[`first`, `last`) and \[`result`,
|
| 114 |
`result + (last - first)`) do not overlap.
|
| 115 |
|
| 116 |
+
[*Note 1*: For the overload with an `ExecutionPolicy`, there might be a
|
| 117 |
performance cost if `iterator_traits<ForwardIterator1>::value_type` is
|
| 118 |
not *Cpp17MoveConstructible*
|
| 119 |
([[cpp17.moveconstructible]]). — *end note*]
|
| 120 |
|
| 121 |
*Effects:* Copies all of the elements referred to by the iterator `i` in
|
|
|
|
| 152 |
|
| 153 |
*Preconditions:* `result` is not in the range (`first`, `last`).
|
| 154 |
|
| 155 |
*Effects:* Copies elements in the range \[`first`, `last`) into the
|
| 156 |
range \[`result - `N, `result`) starting from `last - 1` and proceeding
|
| 157 |
+
to `first`.[^2]
|
| 158 |
+
|
| 159 |
+
For each positive integer n ≤ N, performs
|
| 160 |
`*(result - `n`) = *(last - `n`)`.
|
| 161 |
|
| 162 |
*Returns:*
|
| 163 |
|
| 164 |
- `result - `N for the overload in namespace `std`.
|
|
|
|
| 251 |
|
| 252 |
*Preconditions:* `result` is not in the range (`first`, `last`).
|
| 253 |
|
| 254 |
*Effects:* Moves elements in the range \[`first`, `last`) into the range
|
| 255 |
\[`result - `N, `result`) starting from `last - 1` and proceeding to
|
| 256 |
+
`first`.[^3]
|
| 257 |
+
|
| 258 |
+
For each positive integer n ≤ N, performs `*(result - `n`) = `E.
|
| 259 |
|
| 260 |
*Returns:*
|
| 261 |
|
| 262 |
- `result - `N for the overload in namespace `std`.
|
| 263 |
- `{last, result - `N`}` for the overloads in namespace `ranges`.
|
|
|
|
| 575 |
constexpr OutputIterator fill_n(OutputIterator first, Size n, const T& value);
|
| 576 |
template<class ExecutionPolicy, class ForwardIterator, class Size, class T>
|
| 577 |
ForwardIterator fill_n(ExecutionPolicy&& exec,
|
| 578 |
ForwardIterator first, Size n, const T& value);
|
| 579 |
|
|
|
|
| 580 |
template<class T, output_iterator<const T&> O, sentinel_for<O> S>
|
| 581 |
constexpr O ranges::fill(O first, S last, const T& value);
|
| 582 |
template<class T, output_range<const T&> R>
|
| 583 |
constexpr borrowed_iterator_t<R> ranges::fill(R&& r, const T& value);
|
| 584 |
template<class T, output_iterator<const T&> O>
|
|
|
|
| 588 |
Let N be max(0, `n`) for the `fill_n` algorithms, and `last - first` for
|
| 589 |
the `fill` algorithms.
|
| 590 |
|
| 591 |
*Mandates:* The expression `value` is
|
| 592 |
writable [[iterator.requirements.general]] to the output iterator. The
|
| 593 |
+
type `Size` is convertible to an integral
|
| 594 |
+
type [[conv.integral]], [[class.conv]].
|
| 595 |
|
| 596 |
*Effects:* Assigns `value` through all the iterators in the range
|
| 597 |
\[`first`, `first + `N).
|
| 598 |
|
| 599 |
*Returns:* `first + `N.
|
|
|
|
| 630 |
|
| 631 |
Let N be max(0, `n`) for the `generate_n` algorithms, and `last - first`
|
| 632 |
for the `generate` algorithms.
|
| 633 |
|
| 634 |
*Mandates:* `Size` is convertible to an integral
|
| 635 |
+
type [[conv.integral]], [[class.conv]].
|
| 636 |
|
| 637 |
*Effects:* Assigns the result of successive evaluations of `gen()`
|
| 638 |
through each iterator in the range \[`first`, `first + `N).
|
| 639 |
|
| 640 |
*Returns:* `first + `N.
|
|
|
|
| 695 |
*Returns:* Let j be the end of the resulting range. Returns:
|
| 696 |
|
| 697 |
- j for the overloads in namespace `std`.
|
| 698 |
- `{`j`, last}` for the overloads in namespace `ranges`.
|
| 699 |
|
|
|
|
|
|
|
| 700 |
*Complexity:* Exactly `last - first` applications of the corresponding
|
| 701 |
predicate and any projection.
|
| 702 |
|
| 703 |
+
*Remarks:* Stable [[algorithm.stable]].
|
| 704 |
+
|
| 705 |
[*Note 1*: Each element in the range \[`ret`, `last`), where `ret` is
|
| 706 |
the returned value, has a valid but unspecified state, because the
|
| 707 |
algorithms can eliminate elements by moving from elements that were
|
| 708 |
originally in that range. — *end note*]
|
| 709 |
|
|
|
|
| 767 |
`result`.
|
| 768 |
|
| 769 |
*Preconditions:* The ranges \[`first`, `last`) and \[`result`,
|
| 770 |
`result + (last - first)`) do not overlap.
|
| 771 |
|
| 772 |
+
[*Note 2*: For the overloads with an `ExecutionPolicy`, there might be
|
| 773 |
+
a performance cost if `iterator_traits<ForwardIterator1>::value_type`
|
| 774 |
+
does not meet the *Cpp17MoveConstructible*
|
| 775 |
+
([[cpp17.moveconstructible]]) requirements. — *end note*]
|
| 776 |
|
| 777 |
*Effects:* Copies all the elements referred to by the iterator `i` in
|
| 778 |
the range \[`first`, `last`) for which E is `false`.
|
| 779 |
|
| 780 |
*Returns:*
|
|
|
|
| 819 |
|
| 820 |
- `bool(pred(*(i - 1), *i))` for the overloads in namespace `std`;
|
| 821 |
- `bool(invoke(comp, invoke(proj, *(i - 1)), invoke(proj, *i)))` for the
|
| 822 |
overloads in namespace `ranges`.
|
| 823 |
|
| 824 |
+
*Preconditions:* For the overloads in namespace `std`, `pred` is an
|
| 825 |
equivalence relation and the type of `*first` meets the
|
| 826 |
*Cpp17MoveAssignable* requirements ([[cpp17.moveassignable]]).
|
| 827 |
|
| 828 |
*Effects:* For a nonempty range, eliminates all but the first element
|
| 829 |
from every consecutive group of equivalent elements referred to by the
|
|
|
|
| 894 |
- The ranges \[`first`, `last`) and \[`result`, `result+(last-first)`)
|
| 895 |
do not overlap.
|
| 896 |
- For the overloads in namespace `std`:
|
| 897 |
- The comparison function is an equivalence relation.
|
| 898 |
- For the overloads with no `ExecutionPolicy`, let `T` be the value
|
| 899 |
+
type of `InputIterator`. If `InputIterator` models
|
| 900 |
+
`forward_iterator` [[iterator.concept.forward]], then there are no
|
| 901 |
+
additional requirements for `T`. Otherwise, if `OutputIterator`
|
| 902 |
+
meets the *Cpp17ForwardIterator* requirements and its value type is
|
| 903 |
+
the same as `T`, then `T` meets the *Cpp17CopyAssignable*
|
| 904 |
([[cpp17.copyassignable]]) requirements. Otherwise, `T` meets both
|
| 905 |
the *Cpp17CopyConstructible* ([[cpp17.copyconstructible]]) and
|
| 906 |
*Cpp17CopyAssignable* requirements. \[*Note 1*: For the overloads
|
| 907 |
+
with an `ExecutionPolicy`, there might be a performance cost if the
|
| 908 |
value type of `ForwardIterator1` does not meet both the
|
| 909 |
*Cpp17CopyConstructible* and *Cpp17CopyAssignable*
|
| 910 |
requirements. — *end note*]
|
| 911 |
|
| 912 |
*Effects:* Copies only the first element from every consecutive group of
|
|
|
|
| 1078 |
```
|
| 1079 |
|
| 1080 |
*Effects:* Equivalent to:
|
| 1081 |
|
| 1082 |
``` cpp
|
| 1083 |
+
return ranges::rotate_copy(ranges::begin(r), middle, ranges::end(r), std::move(result));
|
| 1084 |
```
|
| 1085 |
|
| 1086 |
### Sample <a id="alg.random.sample">[[alg.random.sample]]</a>
|
| 1087 |
|
| 1088 |
``` cpp
|
|
|
|
| 1115 |
requirements [[input.iterators]].
|
| 1116 |
- `SampleIterator` meets the *Cpp17OutputIterator*
|
| 1117 |
requirements [[output.iterators]].
|
| 1118 |
- `SampleIterator` meets the *Cpp17RandomAccessIterator*
|
| 1119 |
requirements [[random.access.iterators]] unless `PopulationIterator`
|
| 1120 |
+
models `forward_iterator` [[iterator.concept.forward]].
|
| 1121 |
- `remove_reference_t<UniformRandomBitGenerator>` meets the requirements
|
| 1122 |
of a uniform random bit generator type [[rand.req.urng]].
|
| 1123 |
|
| 1124 |
*Effects:* Copies min(`last - first`, `n`) elements (the *sample*) from
|
| 1125 |
\[`first`, `last`) (the *population*) to `out` such that each possible
|
|
|
|
| 1133 |
*Complexity:* 𝑂(`last - first`).
|
| 1134 |
|
| 1135 |
*Remarks:*
|
| 1136 |
|
| 1137 |
- For the overload in namespace `std`, stable if and only if
|
| 1138 |
+
`PopulationIterator` models `forward_iterator`. For the first overload
|
| 1139 |
+
in namespace `ranges`, stable if and only if `I` models
|
| 1140 |
+
`forward_iterator`.
|
| 1141 |
- To the extent that the implementation of this function makes use of
|
| 1142 |
random numbers, the object `g` serves as the implementation’s source
|
| 1143 |
of randomness.
|
| 1144 |
|
| 1145 |
### Shuffle <a id="alg.random.shuffle">[[alg.random.shuffle]]</a>
|
|
|
|
| 1188 |
typename iterator_traits<ForwardIterator>::difference_type n);
|
| 1189 |
template<class ExecutionPolicy, class ForwardIterator>
|
| 1190 |
ForwardIterator
|
| 1191 |
shift_left(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
|
| 1192 |
typename iterator_traits<ForwardIterator>::difference_type n);
|
| 1193 |
+
|
| 1194 |
+
template<permutable I, sentinel_for<I> S>
|
| 1195 |
+
constexpr subrange<I> ranges::shift_left(I first, S last, iter_difference_t<I> n);
|
| 1196 |
+
template<forward_range R>
|
| 1197 |
+
requires permutable<iterator_t<R>>
|
| 1198 |
+
constexpr borrowed_subrange_t<R> ranges::shift_left(R&& r, range_difference_t<R> n)
|
| 1199 |
```
|
| 1200 |
|
| 1201 |
+
*Preconditions:* `n >= 0` is `true`. For the overloads in namespace
|
| 1202 |
+
`std`, the type of `*first` meets the *Cpp17MoveAssignable*
|
| 1203 |
+
requirements.
|
| 1204 |
|
| 1205 |
*Effects:* If `n == 0` or `n >= last - first`, does nothing. Otherwise,
|
| 1206 |
moves the element from position `first + n + i` into position
|
| 1207 |
+
`first + i` for each non-negative integer `i < (last - first) - n`. For
|
| 1208 |
+
the overloads without an `ExecutionPolicy` template parameter, does so
|
| 1209 |
+
in order starting from `i = 0` and proceeding to
|
| 1210 |
+
`i = (last - first) - n - 1`.
|
| 1211 |
|
| 1212 |
+
*Returns:* Let *NEW_LAST* be `first + (last - first - n)` if
|
| 1213 |
+
`n < last - first`, otherwise `first`.
|
| 1214 |
+
|
| 1215 |
+
- *NEW_LAST* for the overloads in namespace `std`.
|
| 1216 |
+
- `{first, `*`NEW_LAST`*`}` for the overloads in namespace `ranges`.
|
| 1217 |
|
| 1218 |
*Complexity:* At most `(last - first) - n` assignments.
|
| 1219 |
|
| 1220 |
``` cpp
|
| 1221 |
template<class ForwardIterator>
|
|
|
|
| 1224 |
typename iterator_traits<ForwardIterator>::difference_type n);
|
| 1225 |
template<class ExecutionPolicy, class ForwardIterator>
|
| 1226 |
ForwardIterator
|
| 1227 |
shift_right(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
|
| 1228 |
typename iterator_traits<ForwardIterator>::difference_type n);
|
| 1229 |
+
|
| 1230 |
+
template<permutable I, sentinel_for<I> S>
|
| 1231 |
+
constexpr subrange<I> ranges::shift_right(I first, S last, iter_difference_t<I> n);
|
| 1232 |
+
template<forward_range R>
|
| 1233 |
+
requires permutable<iterator_t<R>>
|
| 1234 |
+
constexpr borrowed_subrange_t<R> ranges::shift_right(R&& r, range_difference_t<R> n);
|
| 1235 |
```
|
| 1236 |
|
| 1237 |
+
*Preconditions:* `n >= 0` is `true`. For the overloads in namespace
|
| 1238 |
+
`std`, the type of `*first` meets the *Cpp17MoveAssignable*
|
| 1239 |
+
requirements, and `ForwardIterator` meets the
|
| 1240 |
*Cpp17BidirectionalIterator* requirements [[bidirectional.iterators]] or
|
| 1241 |
the *Cpp17ValueSwappable* requirements.
|
| 1242 |
|
| 1243 |
*Effects:* If `n == 0` or `n >= last - first`, does nothing. Otherwise,
|
| 1244 |
moves the element from position `first + i` into position
|
| 1245 |
`first + n + i` for each non-negative integer `i < (last - first) - n`.
|
| 1246 |
+
Does so in order starting from `i = (last - first) - n - 1` and
|
| 1247 |
+
proceeding to `i = 0` if:
|
|
|
|
| 1248 |
|
| 1249 |
+
- for the overload in namespace `std` without an `ExecutionPolicy`
|
| 1250 |
+
template parameter, `ForwardIterator` meets the
|
| 1251 |
+
*Cpp17BidirectionalIterator* requirements,
|
| 1252 |
+
- for the overloads in namespace `ranges`, `I` models
|
| 1253 |
+
`bidirectional_iterator`.
|
| 1254 |
+
|
| 1255 |
+
*Returns:* Let *NEW_FIRST* be `first + n` if `n < last - first`,
|
| 1256 |
+
otherwise `last`.
|
| 1257 |
+
|
| 1258 |
+
- *NEW_FIRST* for the overloads in namespace `std`.
|
| 1259 |
+
- `{`*`NEW_FIRST`*`, last}` for the overloads in namespace `ranges`.
|
| 1260 |
|
| 1261 |
*Complexity:* At most `(last - first) - n` assignments or swaps.
|
| 1262 |
|