From Jason Turner

[alg.replace]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpmfwzj0kn/{from.md → to.md} +89 -22
tmp/tmpmfwzj0kn/{from.md → to.md} RENAMED
@@ -1,37 +1,66 @@
1
  ### Replace <a id="alg.replace">[[alg.replace]]</a>
2
 
3
  ``` cpp
4
  template<class ForwardIterator, class T>
5
- 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
- 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
 
21
- *Requires:* The expression `*first = new_value` shall be valid.
 
 
 
 
 
 
 
 
22
 
23
  *Effects:* Substitutes elements referred by the iterator `i` in the
24
- range \[`first`, `last`) with `new_value`, when the following
25
- corresponding conditions hold: `*i == old_value`, `pred(*i) != false`.
 
26
 
27
  *Complexity:* Exactly `last - first` applications of the corresponding
28
- predicate.
29
 
30
  ``` cpp
31
  template<class InputIterator, class OutputIterator, class T>
32
- OutputIterator
33
  replace_copy(InputIterator first, InputIterator last,
34
  OutputIterator result,
35
  const T& old_value, const T& new_value);
36
  template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class T>
37
  ForwardIterator2
@@ -39,38 +68,76 @@ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
39
  ForwardIterator1 first, ForwardIterator1 last,
40
  ForwardIterator2 result,
41
  const T& old_value, const T& new_value);
42
 
43
  template<class InputIterator, class OutputIterator, class Predicate, class T>
44
- OutputIterator
45
  replace_copy_if(InputIterator first, InputIterator last,
46
  OutputIterator result,
47
  Predicate pred, const T& new_value);
48
  template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
49
  class Predicate, class T>
50
  ForwardIterator2
51
  replace_copy_if(ExecutionPolicy&& exec,
52
  ForwardIterator1 first, ForwardIterator1 last,
53
  ForwardIterator2 result,
54
  Predicate pred, const T& new_value);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  ```
56
 
57
- *Requires:* The results of the expressions `*first` and `new_value`
58
- shall be writable ([[iterator.requirements.general]]) to the `result`
59
- output iterator. The ranges \[`first`, `last`) and \[`result`,
60
- `result + (last - first)`) shall not overlap.
61
 
62
- *Effects:* Assigns to every iterator `i` in the range \[`result`,
63
- `result + (last - first)`) either `new_value` or
64
- `*(first + (i - result))` depending on whether the following
65
- corresponding conditions hold:
 
 
66
 
67
- ``` cpp
68
- *(first + (i - result)) == old_value
69
- pred(*(first + (i - result))) != false
70
- ```
 
 
 
 
 
 
 
 
 
71
 
72
- *Returns:* `result + (last - first)`.
 
 
73
 
74
  *Complexity:* Exactly `last - first` applications of the corresponding
75
- predicate.
76
 
 
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.
58
 
59
  ``` cpp
60
  template<class InputIterator, class OutputIterator, class T>
61
+ constexpr OutputIterator
62
  replace_copy(InputIterator first, InputIterator last,
63
  OutputIterator result,
64
  const T& old_value, const T& new_value);
65
  template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class T>
66
  ForwardIterator2
 
68
  ForwardIterator1 first, ForwardIterator1 last,
69
  ForwardIterator2 result,
70
  const T& old_value, const T& new_value);
71
 
72
  template<class InputIterator, class OutputIterator, class Predicate, class T>
73
+ constexpr OutputIterator
74
  replace_copy_if(InputIterator first, InputIterator last,
75
  OutputIterator result,
76
  Predicate pred, const T& new_value);
77
  template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
78
  class Predicate, class T>
79
  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