From Jason Turner

[alg.replace]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpo2riiq6z/{from.md → to.md} +107 -28
tmp/tmpo2riiq6z/{from.md → to.md} RENAMED
@@ -1,57 +1,92 @@
1
  ### Replace <a id="alg.replace">[[alg.replace]]</a>
2
 
3
  ``` cpp
4
- template<class ForwardIterator, class T>
5
  constexpr void replace(ForwardIterator first, ForwardIterator last,
6
  const T& old_value, const T& new_value);
7
- template<class ExecutionPolicy, class ForwardIterator, class T>
 
8
  void replace(ExecutionPolicy&& exec,
9
  ForwardIterator first, ForwardIterator last,
10
  const T& old_value, const T& new_value);
11
 
12
- template<class ForwardIterator, class Predicate, class T>
 
13
  constexpr void replace_if(ForwardIterator first, ForwardIterator last,
14
  Predicate pred, const T& new_value);
15
- template<class ExecutionPolicy, class ForwardIterator, class Predicate, class T>
 
16
  void replace_if(ExecutionPolicy&& exec,
17
  ForwardIterator first, ForwardIterator last,
18
  Predicate pred, const T& new_value);
19
 
20
- template<input_iterator I, sentinel_for<I> S, class T1, class T2, class Proj = identity>
 
21
  requires indirectly_writable<I, const T2&> &&
22
  indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T1*>
23
  constexpr I
24
  ranges::replace(I first, S last, const T1& old_value, const T2& new_value, Proj proj = {});
25
- template<input_range R, class T1, class T2, class Proj = identity>
 
26
  requires indirectly_writable<iterator_t<R>, const T2&> &&
27
  indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T1*>
28
  constexpr borrowed_iterator_t<R>
29
  ranges::replace(R&& r, const T1& old_value, const T2& new_value, Proj proj = {});
30
- template<input_iterator I, sentinel_for<I> S, class T, class Proj = identity,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  indirect_unary_predicate<projected<I, Proj>> Pred>
32
  requires indirectly_writable<I, const T&>
33
  constexpr I ranges::replace_if(I first, S last, Pred pred, const T& new_value, Proj proj = {});
34
- template<input_range R, class T, class Proj = identity,
35
  indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
36
  requires indirectly_writable<iterator_t<R>, const T&>
37
  constexpr borrowed_iterator_t<R>
38
  ranges::replace_if(R&& r, Pred pred, const T& new_value, Proj proj = {});
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  ```
40
 
41
- Let E be
42
 
43
  - `bool(*i == old_value)` for `replace`;
44
  - `bool(pred(*i))` for `replace_if`;
45
  - `bool(invoke(proj, *i) == old_value)` for `ranges::replace`;
46
  - `bool(invoke(pred, invoke(proj, *i)))` for `ranges::replace_if`.
47
 
48
  *Mandates:* `new_value` is writable [[iterator.requirements.general]] to
49
  `first`.
50
 
51
  *Effects:* Substitutes elements referred by the iterator `i` in the
52
- range \[`first`, `last`) with `new_value`, when E is `true`.
53
 
54
  *Returns:* `last` for the overloads in namespace `ranges`.
55
 
56
  *Complexity:* Exactly `last - first` applications of the corresponding
57
  predicate and any projection.
@@ -80,64 +115,108 @@ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
80
  replace_copy_if(ExecutionPolicy&& exec,
81
  ForwardIterator1 first, ForwardIterator1 last,
82
  ForwardIterator2 result,
83
  Predicate pred, const T& new_value);
84
 
85
- template<input_iterator I, sentinel_for<I> S, class T1, class T2, output_iterator<const T2&> O,
86
- class Proj = identity>
87
  requires indirectly_copyable<I, O> &&
88
- indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T1*>
 
89
  constexpr ranges::replace_copy_result<I, O>
90
  ranges::replace_copy(I first, S last, O result, const T1& old_value, const T2& new_value,
91
  Proj proj = {});
92
- template<input_range R, class T1, class T2, output_iterator<const T2&> O,
93
- class Proj = identity>
94
  requires indirectly_copyable<iterator_t<R>, O> &&
95
  indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T1*>
 
96
  constexpr ranges::replace_copy_result<borrowed_iterator_t<R>, O>
97
  ranges::replace_copy(R&& r, O result, const T1& old_value, const T2& new_value,
98
  Proj proj = {});
99
 
100
- template<input_iterator I, sentinel_for<I> S, class T, output_iterator<const T&> O,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
  class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred>
102
- requires indirectly_copyable<I, O>
103
  constexpr ranges::replace_copy_if_result<I, O>
104
  ranges::replace_copy_if(I first, S last, O result, Pred pred, const T& new_value,
105
  Proj proj = {});
106
- template<input_range R, class T, output_iterator<const T&> O, class Proj = identity,
107
  indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
108
- requires indirectly_copyable<iterator_t<R>, O>
109
  constexpr ranges::replace_copy_if_result<borrowed_iterator_t<R>, O>
110
  ranges::replace_copy_if(R&& r, O result, Pred pred, const T& new_value,
111
  Proj proj = {});
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  ```
113
 
114
- Let E be
115
 
116
  - `bool(*(first + (i - result)) == old_value)` for `replace_copy`;
117
  - `bool(pred(*(first + (i - result))))` for `replace_copy_if`;
118
  - `bool(invoke(proj, *(first + (i - result))) == old_value)` for
119
  `ranges::replace_copy`;
120
  - `bool(invoke(pred, invoke(proj, *(first + (i - result)))))` for
121
  `ranges::replace_copy_if`.
122
 
 
 
 
 
 
 
123
  *Mandates:* The results of the expressions `*first` and `new_value` are
124
  writable [[iterator.requirements.general]] to `result`.
125
 
126
  *Preconditions:* The ranges \[`first`, `last`) and \[`result`,
127
- `result + (last - first)`) do not overlap.
128
 
129
  *Effects:* Assigns through every iterator `i` in the range \[`result`,
130
- `result + (last - first)`) a new corresponding value
131
 
132
- - `new_value` if E is `true` or
133
  - `*(first + (i - result))` otherwise.
134
 
135
  *Returns:*
136
 
137
- - `result + (last - first)` for the overloads in namespace `std`.
138
- - `{last, result + (last - first)}` for the overloads in namespace
139
- `ranges`.
140
 
141
- *Complexity:* Exactly `last - first` applications of the corresponding
142
- predicate and any projection.
143
 
 
1
  ### Replace <a id="alg.replace">[[alg.replace]]</a>
2
 
3
  ``` cpp
4
+ template<class ForwardIterator, class T = iterator_traits<ForwardIterator>::value_type>
5
  constexpr void replace(ForwardIterator first, ForwardIterator last,
6
  const T& old_value, const T& new_value);
7
+ template<class ExecutionPolicy, class ForwardIterator,
8
+ class T = iterator_traits<ForwardIterator>::value_type>
9
  void replace(ExecutionPolicy&& exec,
10
  ForwardIterator first, ForwardIterator last,
11
  const T& old_value, const T& new_value);
12
 
13
+ template<class ForwardIterator, class Predicate,
14
+ class T = iterator_traits<ForwardIterator>::value_type>
15
  constexpr void replace_if(ForwardIterator first, ForwardIterator last,
16
  Predicate pred, const T& new_value);
17
+ template<class ExecutionPolicy, class ForwardIterator, class Predicate,
18
+ class T = iterator_traits<ForwardIterator>::value_type>
19
  void replace_if(ExecutionPolicy&& exec,
20
  ForwardIterator first, ForwardIterator last,
21
  Predicate pred, const T& new_value);
22
 
23
+ template<input_iterator I, sentinel_for<I> S, class Proj = identity,
24
+ class T1 = projected_value_t<I, Proj>, class T2 = T1>
25
  requires indirectly_writable<I, const T2&> &&
26
  indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T1*>
27
  constexpr I
28
  ranges::replace(I first, S last, const T1& old_value, const T2& new_value, Proj proj = {});
29
+ template<input_range R, class Proj = identity,
30
+ class T1 = projected_value_t<iterator_t<R>, Proj>, class T2 = T1>
31
  requires indirectly_writable<iterator_t<R>, const T2&> &&
32
  indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T1*>
33
  constexpr borrowed_iterator_t<R>
34
  ranges::replace(R&& r, const T1& old_value, const T2& new_value, Proj proj = {});
35
+
36
+ template<execution-policy Ep, random_access_iterator I, sized_sentinel_for<I> S,
37
+ class Proj = identity, class T1 = projected_value_t<I, Proj>, class T2 = T1>
38
+ requires indirectly_writable<I, const T2&> &&
39
+ indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T1*>
40
+ I ranges::replace(Ep&& exec, I first, S last,
41
+ const T1& old_value, const T2& new_value, Proj proj = {});
42
+ template<execution-policy Ep, sized-random-access-range R, class Proj = identity,
43
+ class T1 = projected_value_t<iterator_t<R>, Proj>, class T2 = T1>
44
+ requires indirectly_writable<iterator_t<R>, const T2&> &&
45
+ indirect_binary_predicate<ranges::equal_to,
46
+ projected<iterator_t<R>, Proj>, const T1*>
47
+ borrowed_iterator_t<R>
48
+ ranges::replace(Ep&& exec, R&& r, const T1& old_value, const T2& new_value,
49
+ Proj proj = {});
50
+
51
+ template<input_iterator I, sentinel_for<I> S, class Proj = identity,
52
+ class T = projected_value_t<I, Proj>,
53
  indirect_unary_predicate<projected<I, Proj>> Pred>
54
  requires indirectly_writable<I, const T&>
55
  constexpr I ranges::replace_if(I first, S last, Pred pred, const T& new_value, Proj proj = {});
56
+ template<input_range R, class Proj = identity, class T = projected_value_t<iterator_t<R>, Proj>,
57
  indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
58
  requires indirectly_writable<iterator_t<R>, const T&>
59
  constexpr borrowed_iterator_t<R>
60
  ranges::replace_if(R&& r, Pred pred, const T& new_value, Proj proj = {});
61
+
62
+ template<execution-policy Ep, random_access_iterator I, sized_sentinel_for<I> S,
63
+ class Proj = identity, class T = projected_value_t<I, Proj>,
64
+ indirect_unary_predicate<projected<I, Proj>> Pred>
65
+ requires indirectly_writable<I, const T&>
66
+ I ranges::replace_if(Ep&& exec, I first, S last, Pred pred,
67
+ const T& new_value, Proj proj = {});
68
+ template<execution-policy Ep, sized-random-access-range R, class Proj = identity,
69
+ class T = projected_value_t<iterator_t<R>, Proj>,
70
+ indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
71
+ requires indirectly_writable<iterator_t<R>, const T&>
72
+ borrowed_iterator_t<R>
73
+ ranges::replace_if(Ep&& exec, R&& r, Pred pred, const T& new_value, Proj proj = {});
74
  ```
75
 
76
+ Let E(`i`) be
77
 
78
  - `bool(*i == old_value)` for `replace`;
79
  - `bool(pred(*i))` for `replace_if`;
80
  - `bool(invoke(proj, *i) == old_value)` for `ranges::replace`;
81
  - `bool(invoke(pred, invoke(proj, *i)))` for `ranges::replace_if`.
82
 
83
  *Mandates:* `new_value` is writable [[iterator.requirements.general]] to
84
  `first`.
85
 
86
  *Effects:* Substitutes elements referred by the iterator `i` in the
87
+ range \[`first`, `last`) with `new_value`, when E(`i`) is `true`.
88
 
89
  *Returns:* `last` for the overloads in namespace `ranges`.
90
 
91
  *Complexity:* Exactly `last - first` applications of the corresponding
92
  predicate and any projection.
 
115
  replace_copy_if(ExecutionPolicy&& exec,
116
  ForwardIterator1 first, ForwardIterator1 last,
117
  ForwardIterator2 result,
118
  Predicate pred, const T& new_value);
119
 
120
+ template<input_iterator I, sentinel_for<I> S, class O,
121
+ class Proj = identity, class T1 = projected_value_t<I, Proj>, class T2 = iter_value_t<O>>
122
  requires indirectly_copyable<I, O> &&
123
+ indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T1*> &&
124
+ output_iterator<O, const T2&>
125
  constexpr ranges::replace_copy_result<I, O>
126
  ranges::replace_copy(I first, S last, O result, const T1& old_value, const T2& new_value,
127
  Proj proj = {});
128
+ template<input_range R, class O, class Proj = identity,
129
+ class T1 = projected_value_t<iterator_t<R>, Proj>, class T2 = iter_value_t<O>>
130
  requires indirectly_copyable<iterator_t<R>, O> &&
131
  indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T1*>
132
+ && output_iterator<O, const T2&>
133
  constexpr ranges::replace_copy_result<borrowed_iterator_t<R>, O>
134
  ranges::replace_copy(R&& r, O result, const T1& old_value, const T2& new_value,
135
  Proj proj = {});
136
 
137
+ template<execution-policy Ep, random_access_iterator I, sized_sentinel_for<I> S,
138
+ random_access_iterator O, sized_sentinel_for<O> OutS,
139
+ class Proj = identity,
140
+ class T1 = projected_value_t<I, Proj>, class T2 = iter_value_t<O>>
141
+ requires indirectly_copyable<I, O> &&
142
+ indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T1*> &&
143
+ indirectly_writable<O, const T2&>
144
+ ranges::replace_copy_result<I, O>
145
+ ranges::replace_copy(Ep&& exec, I first, S last, O result, OutS result_last,
146
+ const T1& old_value, const T2& new_value, Proj proj = {});
147
+ template<execution-policy Ep, sized-random-access-range R, sized-random-access-range OutR,
148
+ class Proj = identity, class T1 = projected_value_t<iterator_t<R>, Proj>,
149
+ class T2 = range_value_t<OutR>>
150
+ requires indirectly_copyable<iterator_t<R>, iterator_t<OutR>> &&
151
+ indirect_binary_predicate<ranges::equal_to,
152
+ projected<iterator_t<R>, Proj>, const T1*> &&
153
+ indirectly_writable<iterator_t<OutR>, const T2&>
154
+ ranges::replace_copy_result<borrowed_iterator_t<R>, borrowed_iterator_t<OutR>>
155
+ ranges::replace_copy(Ep&& exec, R&& r, OutR&& result_r, const T1& old_value,
156
+ const T2& new_value, Proj proj = {});
157
+
158
+ template<input_iterator I, sentinel_for<I> S,class O, class T = iter_value_t<O>,
159
  class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred>
160
+ requires indirectly_copyable<I, O> && output_iterator<O, const T&>
161
  constexpr ranges::replace_copy_if_result<I, O>
162
  ranges::replace_copy_if(I first, S last, O result, Pred pred, const T& new_value,
163
  Proj proj = {});
164
+ template<input_range R, class O, class T = iter_value_t<O>, class Proj = identity,
165
  indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
166
+ requires indirectly_copyable<iterator_t<R>, O> && output_iterator<O, const T&>
167
  constexpr ranges::replace_copy_if_result<borrowed_iterator_t<R>, O>
168
  ranges::replace_copy_if(R&& r, O result, Pred pred, const T& new_value,
169
  Proj proj = {});
170
+
171
+ template<execution-policy Ep, random_access_iterator I, sized_sentinel_for<I> S,
172
+ random_access_iterator O, sized_sentinel_for<O> OutS, class T = iter_value_t<O>,
173
+ class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred>
174
+ requires indirectly_copyable<I, O> && indirectly_writable<O, const T&>
175
+ ranges::replace_copy_if_result<I, O>
176
+ ranges::replace_copy_if(Ep&& exec, I first, S last, O result, OutS result_last,
177
+ Pred pred, const T& new_value, Proj proj = {});
178
+ template<execution-policy Ep, sized-random-access-range R, sized-random-access-range OutR,
179
+ class T = range_value_t<OutR>, class Proj = identity,
180
+ indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
181
+ requires indirectly_copyable<iterator_t<R>, iterator_t<OutR>> &&
182
+ indirectly_writable<OutR, const T&>
183
+ ranges::replace_copy_if_result<borrowed_iterator_t<R>, borrowed_iterator_t<OutR>>
184
+ ranges::replace_copy_if(Ep&& exec, R&& r, OutR&& result_r, Pred pred, const T& new_value,
185
+ Proj proj = {});
186
  ```
187
 
188
+ Let E(`i`) be
189
 
190
  - `bool(*(first + (i - result)) == old_value)` for `replace_copy`;
191
  - `bool(pred(*(first + (i - result))))` for `replace_copy_if`;
192
  - `bool(invoke(proj, *(first + (i - result))) == old_value)` for
193
  `ranges::replace_copy`;
194
  - `bool(invoke(pred, invoke(proj, *(first + (i - result)))))` for
195
  `ranges::replace_copy_if`.
196
 
197
+ Let:
198
+
199
+ - `result_last` be `result + (last - first)` for the overloads with no
200
+ parameter `result_last` or `result_r`;
201
+ - N be min(`last - first`, `result_last - result`).
202
+
203
  *Mandates:* The results of the expressions `*first` and `new_value` are
204
  writable [[iterator.requirements.general]] to `result`.
205
 
206
  *Preconditions:* The ranges \[`first`, `last`) and \[`result`,
207
+ `result + `N) do not overlap.
208
 
209
  *Effects:* Assigns through every iterator `i` in the range \[`result`,
210
+ `result + `N) a new corresponding value
211
 
212
+ - `new_value` if E(`i`) is `true` or
213
  - `*(first + (i - result))` otherwise.
214
 
215
  *Returns:*
216
 
217
+ - `result + `N for the overloads in namespace `std`.
218
+ - `{first + `N`, result + `N`}` for the overloads in namespace `ranges`.
 
219
 
220
+ *Complexity:* Exactly N applications of the corresponding predicate and
221
+ any projection.
222