From Jason Turner

[alg.rotate]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpyw2dl46v/{from.md → to.md} +57 -17
tmp/tmpyw2dl46v/{from.md → to.md} RENAMED
@@ -1,53 +1,93 @@
1
  ### Rotate <a id="alg.rotate">[[alg.rotate]]</a>
2
 
3
  ``` cpp
4
  template<class ForwardIterator>
5
- ForwardIterator
6
  rotate(ForwardIterator first, ForwardIterator middle, ForwardIterator last);
7
  template<class ExecutionPolicy, class ForwardIterator>
8
  ForwardIterator
9
  rotate(ExecutionPolicy&& exec,
10
  ForwardIterator first, ForwardIterator middle, ForwardIterator last);
 
 
 
11
  ```
12
 
13
- *Requires:* \[`first`, `middle`) and \[`middle`, `last`) shall be valid
14
- ranges. `ForwardIterator` shall satisfy the requirements of
15
- `ValueSwappable` ([[swappable.requirements]]). The type of `*first`
16
- shall satisfy the requirements of `MoveConstructible`
17
- (Table  [[tab:moveconstructible]]) and the requirements of
18
- `MoveAssignable` (Table  [[tab:moveassignable]]).
19
 
20
  *Effects:* For each non-negative integer `i < (last - first)`, places
21
  the element from the position `first + i` into position
22
  `first + (i + (last - middle)) % (last - first)`.
23
 
24
- *Returns:* `first + (last - middle)`.
25
 
26
- *Remarks:* This is a left rotate.
 
 
 
 
27
 
28
  *Complexity:* At most `last - first` swaps.
29
 
 
 
 
 
 
 
 
 
 
30
  ``` cpp
31
  template<class ForwardIterator, class OutputIterator>
32
- OutputIterator
33
  rotate_copy(ForwardIterator first, ForwardIterator middle, ForwardIterator last,
34
  OutputIterator result);
35
  template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
36
  ForwardIterator2
37
  rotate_copy(ExecutionPolicy&& exec,
38
  ForwardIterator1 first, ForwardIterator1 middle, ForwardIterator1 last,
39
  ForwardIterator2 result);
 
 
 
 
 
40
  ```
41
 
42
- *Requires:* The ranges \[`first`, `last`) and \[`result`,
43
- `result + (last - first)`) shall not overlap.
 
 
 
44
 
45
  *Effects:* Copies the range \[`first`, `last`) to the range \[`result`,
46
- `result + (last - first)`) such that for each non-negative integer
47
- `i < (last - first)` the following assignment takes place:
48
- `*(result + i) = *(first + (i + (middle - first)) % (last - first))`.
49
 
50
- *Returns:* `result + (last - first)`.
51
 
52
- *Complexity:* Exactly `last - first` assignments.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
 
 
1
  ### Rotate <a id="alg.rotate">[[alg.rotate]]</a>
2
 
3
  ``` cpp
4
  template<class ForwardIterator>
5
+ constexpr ForwardIterator
6
  rotate(ForwardIterator first, ForwardIterator middle, ForwardIterator last);
7
  template<class ExecutionPolicy, class ForwardIterator>
8
  ForwardIterator
9
  rotate(ExecutionPolicy&& exec,
10
  ForwardIterator first, ForwardIterator middle, ForwardIterator last);
11
+
12
+ template<permutable I, sentinel_for<I> S>
13
+ constexpr subrange<I> ranges::rotate(I first, I middle, S last);
14
  ```
15
 
16
+ *Preconditions:* \[`first`, `middle`) and \[`middle`, `last`) are valid
17
+ ranges. For the overloads in namespace `std`, `ForwardIterator` meets
18
+ the *Cpp17ValueSwappable* requirements [[swappable.requirements]], and
19
+ the type of `*first` meets the *Cpp17MoveConstructible*
20
+ ([[cpp17.moveconstructible]]) and *Cpp17MoveAssignable*
21
+ ([[cpp17.moveassignable]]) requirements.
22
 
23
  *Effects:* For each non-negative integer `i < (last - first)`, places
24
  the element from the position `first + i` into position
25
  `first + (i + (last - middle)) % (last - first)`.
26
 
27
+ [*Note 1*: This is a left rotate. — *end note*]
28
 
29
+ *Returns:*
30
+
31
+ - `first + (last - middle)` for the overloads in namespace `std`.
32
+ - `{first + (last - middle), last}` for the overload in namespace
33
+ `ranges`.
34
 
35
  *Complexity:* At most `last - first` swaps.
36
 
37
+ ``` cpp
38
+ template<forward_range R>
39
+ requires permutable<iterator_t<R>>
40
+ constexpr borrowed_subrange_t<R> ranges::rotate(R&& r, iterator_t<R> middle);
41
+ ```
42
+
43
+ *Effects:* Equivalent to:
44
+ `return ranges::rotate(ranges::begin(r), middle, ranges::end(r));`
45
+
46
  ``` cpp
47
  template<class ForwardIterator, class OutputIterator>
48
+ constexpr OutputIterator
49
  rotate_copy(ForwardIterator first, ForwardIterator middle, ForwardIterator last,
50
  OutputIterator result);
51
  template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
52
  ForwardIterator2
53
  rotate_copy(ExecutionPolicy&& exec,
54
  ForwardIterator1 first, ForwardIterator1 middle, ForwardIterator1 last,
55
  ForwardIterator2 result);
56
+
57
+ template<forward_iterator I, sentinel_for<I> S, weakly_incrementable O>
58
+ requires indirectly_copyable<I, O>
59
+ constexpr ranges::rotate_copy_result<I, O>
60
+ ranges::rotate_copy(I first, I middle, S last, O result);
61
  ```
62
 
63
+ Let N be `last - first`.
64
+
65
+ *Preconditions:* \[`first`, `middle`) and \[`middle`, `last`) are valid
66
+ ranges. The ranges \[`first`, `last`) and \[`result`, `result + `N) do
67
+ not overlap.
68
 
69
  *Effects:* Copies the range \[`first`, `last`) to the range \[`result`,
70
+ `result + `N) such that for each non-negative integer i < N the
71
+ following assignment takes place:
72
+ `*(result + `i`) = *(first + (`i` + (middle - first)) % `N`)`.
73
 
74
+ *Returns:*
75
 
76
+ - `result + `N for the overloads in namespace `std`.
77
+ - `{last, result + `N`}` for the overload in namespace `ranges`.
78
+
79
+ *Complexity:* Exactly N assignments.
80
+
81
+ ``` cpp
82
+ template<forward_range R, weakly_incrementable O>
83
+ requires indirectly_copyable<iterator_t<R>, O>
84
+ constexpr ranges::rotate_copy_result<borrowed_iterator_t<R>, O>
85
+ ranges::rotate_copy(R&& r, iterator_t<R> middle, O result);
86
+ ```
87
+
88
+ *Effects:* Equivalent to:
89
+
90
+ ``` cpp
91
+ return ranges::rotate_copy(ranges::begin(r), middle, ranges::end(r), result);
92
+ ```
93