From Jason Turner

[alg.copy]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp7cl9qa7o/{from.md → to.md} +93 -30
tmp/tmp7cl9qa7o/{from.md → to.md} RENAMED
@@ -1,33 +1,45 @@
1
  ### Copy <a id="alg.copy">[[alg.copy]]</a>
2
 
3
  ``` cpp
4
  template<class InputIterator, class OutputIterator>
5
- OutputIterator copy(InputIterator first, InputIterator last,
6
  OutputIterator result);
 
 
 
 
 
 
 
7
  ```
8
 
9
- *Requires:* `result` shall not be in the range \[`first`, `last`).
 
 
10
 
11
  *Effects:* Copies elements in the range \[`first`, `last`) into the
12
- range \[`result`, `result + (last - first)`) starting from `first` and
13
- proceeding to `last`. For each non-negative integer
14
- `n < (last - first)`, performs `*(result + n) = *(first + n)`.
15
 
16
- *Returns:* `result + (last - first)`.
17
 
18
- *Complexity:* Exactly `last - first` assignments.
 
 
 
19
 
20
  ``` cpp
21
  template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
22
  ForwardIterator2 copy(ExecutionPolicy&& policy,
23
  ForwardIterator1 first, ForwardIterator1 last,
24
  ForwardIterator2 result);
25
  ```
26
 
27
- *Requires:* The ranges \[`first`, `last`) and \[`result`,
28
- `result + (last - first)`) shall not overlap.
29
 
30
  *Effects:* Copies elements in the range \[`first`, `last`) into the
31
  range \[`result`, `result + (last - first)`). For each non-negative
32
  integer `n < (last - first)`, performs `*(result + n) = *(first + n)`.
33
 
@@ -35,67 +47,118 @@ integer `n < (last - first)`, performs `*(result + n) = *(first + n)`.
35
 
36
  *Complexity:* Exactly `last - first` assignments.
37
 
38
  ``` cpp
39
  template<class InputIterator, class Size, class OutputIterator>
40
- OutputIterator copy_n(InputIterator first, Size n,
41
  OutputIterator result);
42
  template<class ExecutionPolicy, class ForwardIterator1, class Size, class ForwardIterator2>
43
  ForwardIterator2 copy_n(ExecutionPolicy&& exec,
44
  ForwardIterator1 first, Size n,
45
  ForwardIterator2 result);
 
 
 
 
 
46
  ```
47
 
48
- *Effects:* For each non-negative integer i < n, performs
 
 
 
 
 
49
  `*(result + i) = *(first + i)`.
50
 
51
- *Returns:* `result + n`.
52
 
53
- *Complexity:* Exactly `n` assignments.
 
 
 
54
 
55
  ``` cpp
56
  template<class InputIterator, class OutputIterator, class Predicate>
57
- OutputIterator copy_if(InputIterator first, InputIterator last,
58
  OutputIterator result, Predicate pred);
59
- template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class Predicate>
 
60
  ForwardIterator2 copy_if(ExecutionPolicy&& exec,
61
  ForwardIterator1 first, ForwardIterator1 last,
62
  ForwardIterator2 result, Predicate pred);
 
 
 
 
 
 
 
 
 
 
 
63
  ```
64
 
65
- *Requires:* The ranges \[`first`, `last`) and \[`result`,
66
- `result + (last - first)`) shall not overlap.
 
 
 
 
 
 
 
 
 
67
 
68
  [*Note 1*: For the overload with an `ExecutionPolicy`, there may be a
69
  performance cost if `iterator_traits<ForwardIterator1>::value_type` is
70
- not `MoveConstructible`
71
- (Table  [[tab:moveconstructible]]). — *end note*]
72
 
73
  *Effects:* Copies all of the elements referred to by the iterator `i` in
74
- the range \[`first`, `last`) for which `pred(*i)` is `true`.
75
 
76
- *Returns:* The end of the resulting range.
 
 
 
77
 
78
  *Complexity:* Exactly `last - first` applications of the corresponding
79
- predicate.
80
 
81
- *Remarks:* Stable ([[algorithm.stable]]).
82
 
83
  ``` cpp
84
  template<class BidirectionalIterator1, class BidirectionalIterator2>
85
- BidirectionalIterator2
86
  copy_backward(BidirectionalIterator1 first,
87
  BidirectionalIterator1 last,
88
  BidirectionalIterator2 result);
 
 
 
 
 
 
 
 
 
89
  ```
90
 
91
- *Requires:* `result` shall not be in the range (`first`, `last`).
 
 
92
 
93
  *Effects:* Copies elements in the range \[`first`, `last`) into the
94
- range \[`result - (last-first)`, `result`) starting from `last - 1` and
95
- proceeding to `first`.[^2] For each positive integer
96
- `n <= (last - first)`, performs `*(result - n) = *(last - n)`.
97
 
98
- *Returns:* `result - (last - first)`.
99
 
100
- *Complexity:* Exactly `last - first` assignments.
 
 
 
101
 
 
1
  ### Copy <a id="alg.copy">[[alg.copy]]</a>
2
 
3
  ``` cpp
4
  template<class InputIterator, class OutputIterator>
5
+ constexpr OutputIterator copy(InputIterator first, InputIterator last,
6
  OutputIterator result);
7
+
8
+ template<input_iterator I, sentinel_for<I> S, weakly_incrementable O>
9
+ requires indirectly_copyable<I, O>
10
+ constexpr ranges::copy_result<I, O> ranges::copy(I first, S last, O result);
11
+ template<input_range R, weakly_incrementable O>
12
+ requires indirectly_copyable<iterator_t<R>, O>
13
+ constexpr ranges::copy_result<borrowed_iterator_t<R>, O> ranges::copy(R&& r, O result);
14
  ```
15
 
16
+ Let N be `last - first`.
17
+
18
+ *Preconditions:* `result` is not in the range \[`first`, `last`).
19
 
20
  *Effects:* Copies elements in the range \[`first`, `last`) into the
21
+ range \[`result`, `result + `N) starting from `first` and proceeding to
22
+ `last`. For each non-negative integer n < N, performs
23
+ `*(result + `n`) = *(first + `n`)`.
24
 
25
+ *Returns:*
26
 
27
+ - `result + `N for the overload in namespace `std`.
28
+ - `{last, result + `N`}` for the overloads in namespace `ranges`.
29
+
30
+ *Complexity:* Exactly N assignments.
31
 
32
  ``` cpp
33
  template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
34
  ForwardIterator2 copy(ExecutionPolicy&& policy,
35
  ForwardIterator1 first, ForwardIterator1 last,
36
  ForwardIterator2 result);
37
  ```
38
 
39
+ *Preconditions:* The ranges \[`first`, `last`) and \[`result`,
40
+ `result + (last - first)`) do not overlap.
41
 
42
  *Effects:* Copies elements in the range \[`first`, `last`) into the
43
  range \[`result`, `result + (last - first)`). For each non-negative
44
  integer `n < (last - first)`, performs `*(result + n) = *(first + n)`.
45
 
 
47
 
48
  *Complexity:* Exactly `last - first` assignments.
49
 
50
  ``` cpp
51
  template<class InputIterator, class Size, class OutputIterator>
52
+ constexpr OutputIterator copy_n(InputIterator first, Size n,
53
  OutputIterator result);
54
  template<class ExecutionPolicy, class ForwardIterator1, class Size, class ForwardIterator2>
55
  ForwardIterator2 copy_n(ExecutionPolicy&& exec,
56
  ForwardIterator1 first, Size n,
57
  ForwardIterator2 result);
58
+
59
+ template<input_iterator I, weakly_incrementable O>
60
+ requires indirectly_copyable<I, O>
61
+ constexpr ranges::copy_n_result<I, O>
62
+ ranges::copy_n(I first, iter_difference_t<I> n, O result);
63
  ```
64
 
65
+ Let N be max(0, `n`).
66
+
67
+ *Mandates:* The type `Size` is convertible to an integral
68
+ type ([[conv.integral]], [[class.conv]]).
69
+
70
+ *Effects:* For each non-negative integer i < N, performs
71
  `*(result + i) = *(first + i)`.
72
 
73
+ *Returns:*
74
 
75
+ - `result + `N for the overloads in namespace `std`.
76
+ - `{first + `N`, result + `N`}` for the overload in namespace `ranges`.
77
+
78
+ *Complexity:* Exactly N assignments.
79
 
80
  ``` cpp
81
  template<class InputIterator, class OutputIterator, class Predicate>
82
+ constexpr OutputIterator copy_if(InputIterator first, InputIterator last,
83
  OutputIterator result, Predicate pred);
84
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
85
+ class Predicate>
86
  ForwardIterator2 copy_if(ExecutionPolicy&& exec,
87
  ForwardIterator1 first, ForwardIterator1 last,
88
  ForwardIterator2 result, Predicate pred);
89
+
90
+ template<input_iterator I, sentinel_for<I> S, weakly_incrementable O, class Proj = identity,
91
+ indirect_unary_predicate<projected<I, Proj>> Pred>
92
+ requires indirectly_copyable<I, O>
93
+ constexpr ranges::copy_if_result<I, O>
94
+ ranges::copy_if(I first, S last, O result, Pred pred, Proj proj = {});
95
+ template<input_range R, weakly_incrementable O, class Proj = identity,
96
+ indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
97
+ requires indirectly_copyable<iterator_t<R>, O>
98
+ constexpr ranges::copy_if_result<borrowed_iterator_t<R>, O>
99
+ ranges::copy_if(R&& r, O result, Pred pred, Proj proj = {});
100
  ```
101
 
102
+ Let E be:
103
+
104
+ - `bool(pred(*i))` for the overloads in namespace `std`;
105
+ - `bool(invoke(pred, invoke(proj, *i)))` for the overloads in namespace
106
+ `ranges`,
107
+
108
+ and N be the number of iterators `i` in the range \[`first`, `last`) for
109
+ which the condition E holds.
110
+
111
+ *Preconditions:* The ranges \[`first`, `last`) and \[`result`,
112
+ `result + (last - first)`) do not overlap.
113
 
114
  [*Note 1*: For the overload with an `ExecutionPolicy`, there may be a
115
  performance cost if `iterator_traits<ForwardIterator1>::value_type` is
116
+ not *Cpp17MoveConstructible*
117
+ ([[cpp17.moveconstructible]]). — *end note*]
118
 
119
  *Effects:* Copies all of the elements referred to by the iterator `i` in
120
+ the range \[`first`, `last`) for which E is `true`.
121
 
122
+ *Returns:*
123
+
124
+ - `result + `N for the overloads in namespace `std`.
125
+ - `{last, result + `N`}` for the overloads in namespace `ranges`.
126
 
127
  *Complexity:* Exactly `last - first` applications of the corresponding
128
+ predicate and any projection.
129
 
130
+ *Remarks:* Stable [[algorithm.stable]].
131
 
132
  ``` cpp
133
  template<class BidirectionalIterator1, class BidirectionalIterator2>
134
+ constexpr BidirectionalIterator2
135
  copy_backward(BidirectionalIterator1 first,
136
  BidirectionalIterator1 last,
137
  BidirectionalIterator2 result);
138
+
139
+ template<bidirectional_iterator I1, sentinel_for<I1> S1, bidirectional_iterator I2>
140
+ requires indirectly_copyable<I1, I2>
141
+ constexpr ranges::copy_backward_result<I1, I2>
142
+ ranges::copy_backward(I1 first, S1 last, I2 result);
143
+ template<bidirectional_range R, bidirectional_iterator I>
144
+ requires indirectly_copyable<iterator_t<R>, I>
145
+ constexpr ranges::copy_backward_result<borrowed_iterator_t<R>, I>
146
+ ranges::copy_backward(R&& r, I result);
147
  ```
148
 
149
+ Let N be `last - first`.
150
+
151
+ *Preconditions:* `result` is not in the range (`first`, `last`).
152
 
153
  *Effects:* Copies elements in the range \[`first`, `last`) into the
154
+ range \[`result - `N, `result`) starting from `last - 1` and proceeding
155
+ to `first`. [^2] For each positive integer n ≤ N, performs
156
+ `*(result - `n`) = *(last - `n`)`.
157
 
158
+ *Returns:*
159
 
160
+ - `result - `N for the overload in namespace `std`.
161
+ - `{last, result - `N`}` for the overloads in namespace `ranges`.
162
+
163
+ *Complexity:* Exactly N assignments.
164