From Jason Turner

[alg.reverse]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpqhpn7p0p/{from.md → to.md} +36 -13
tmp/tmpqhpn7p0p/{from.md → to.md} RENAMED
@@ -1,45 +1,68 @@
1
  ### Reverse <a id="alg.reverse">[[alg.reverse]]</a>
2
 
3
  ``` cpp
4
  template<class BidirectionalIterator>
5
- void reverse(BidirectionalIterator first, BidirectionalIterator last);
6
  template<class ExecutionPolicy, class BidirectionalIterator>
7
  void reverse(ExecutionPolicy&& exec,
8
  BidirectionalIterator first, BidirectionalIterator last);
 
 
 
 
 
 
 
9
  ```
10
 
11
- *Requires:* `*first` shall be swappable ([[swappable.requirements]]).
 
 
12
 
13
  *Effects:* For each non-negative integer `i < (last - first) / 2`,
14
- applies `iter_swap` to all pairs of iterators
 
15
  `first + i, (last - i) - 1`.
16
 
17
- *Requires:* `BidirectionalIterator` shall satisfy the requirements of
18
- `ValueSwappable` ([[swappable.requirements]]).
19
 
20
  *Complexity:* Exactly `(last - first)/2` swaps.
21
 
22
  ``` cpp
23
  template<class BidirectionalIterator, class OutputIterator>
24
- OutputIterator
25
  reverse_copy(BidirectionalIterator first, BidirectionalIterator last,
26
  OutputIterator result);
27
  template<class ExecutionPolicy, class BidirectionalIterator, class ForwardIterator>
28
  ForwardIterator
29
  reverse_copy(ExecutionPolicy&& exec,
30
  BidirectionalIterator first, BidirectionalIterator last,
31
  ForwardIterator result);
 
 
 
 
 
 
 
 
 
32
  ```
33
 
34
- *Requires:* The ranges \[`first`, `last`) and \[`result`,
35
- `result + (last - first)`) shall not overlap.
 
 
36
 
37
  *Effects:* Copies the range \[`first`, `last`) to the range \[`result`,
38
- `result + (last - first)`) such that for every non-negative integer
39
- `i < (last - first)` the following assignment takes place:
40
- `*(result + (last - first) - 1 - i) = *(first + i)`.
41
 
42
- *Returns:* `result + (last - first)`.
43
 
44
- *Complexity:* Exactly `last - first` assignments.
 
 
 
45
 
 
1
  ### Reverse <a id="alg.reverse">[[alg.reverse]]</a>
2
 
3
  ``` cpp
4
  template<class BidirectionalIterator>
5
+ constexpr void reverse(BidirectionalIterator first, BidirectionalIterator last);
6
  template<class ExecutionPolicy, class BidirectionalIterator>
7
  void reverse(ExecutionPolicy&& exec,
8
  BidirectionalIterator first, BidirectionalIterator last);
9
+
10
+ template<bidirectional_iterator I, sentinel_for<I> S>
11
+ requires permutable<I>
12
+ constexpr I ranges::reverse(I first, S last);
13
+ template<bidirectional_range R>
14
+ requires permutable<iterator_t<R>>
15
+ constexpr borrowed_iterator_t<R> ranges::reverse(R&& r);
16
  ```
17
 
18
+ *Preconditions:* For the overloads in namespace `std`,
19
+ `BidirectionalIterator` meets the *Cpp17ValueSwappable*
20
+ requirements [[swappable.requirements]].
21
 
22
  *Effects:* For each non-negative integer `i < (last - first) / 2`,
23
+ applies `std::iter_swap`, or `ranges::iter_swap` for the overloads in
24
+ namespace `ranges`, to all pairs of iterators
25
  `first + i, (last - i) - 1`.
26
 
27
+ *Returns:* `last` for the overloads in namespace `ranges`.
 
28
 
29
  *Complexity:* Exactly `(last - first)/2` swaps.
30
 
31
  ``` cpp
32
  template<class BidirectionalIterator, class OutputIterator>
33
+ constexpr OutputIterator
34
  reverse_copy(BidirectionalIterator first, BidirectionalIterator last,
35
  OutputIterator result);
36
  template<class ExecutionPolicy, class BidirectionalIterator, class ForwardIterator>
37
  ForwardIterator
38
  reverse_copy(ExecutionPolicy&& exec,
39
  BidirectionalIterator first, BidirectionalIterator last,
40
  ForwardIterator result);
41
+
42
+ template<bidirectional_iterator I, sentinel_for<I> S, weakly_incrementable O>
43
+ requires indirectly_copyable<I, O>
44
+ constexpr ranges::reverse_copy_result<I, O>
45
+ ranges::reverse_copy(I first, S last, O result);
46
+ template<bidirectional_range R, weakly_incrementable O>
47
+ requires indirectly_copyable<iterator_t<R>, O>
48
+ constexpr ranges::reverse_copy_result<borrowed_iterator_t<R>, O>
49
+ ranges::reverse_copy(R&& r, O result);
50
  ```
51
 
52
+ Let N be `last - first`.
53
+
54
+ *Preconditions:* The ranges \[`first`, `last`) and \[`result`,
55
+ `result + `N) do not overlap.
56
 
57
  *Effects:* Copies the range \[`first`, `last`) to the range \[`result`,
58
+ `result + `N) such that for every non-negative integer `i < `N the
59
+ following assignment takes place:
60
+ `*(result + `N` - 1 - i) = *(first + i)`.
61
 
62
+ *Returns:*
63
 
64
+ - `result + `N for the overloads in namespace `std`.
65
+ - `{last, result + `N`}` for the overloads in namespace `ranges`.
66
+
67
+ *Complexity:* Exactly N assignments.
68