From Jason Turner

[alg.remove]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpsl3o3_s5/{from.md → to.md} +89 -24
tmp/tmpsl3o3_s5/{from.md → to.md} RENAMED
@@ -1,81 +1,146 @@
1
  ### Remove <a id="alg.remove">[[alg.remove]]</a>
2
 
3
  ``` cpp
4
  template<class ForwardIterator, class T>
5
- ForwardIterator remove(ForwardIterator first, ForwardIterator last,
6
  const T& value);
7
  template<class ExecutionPolicy, class ForwardIterator, class T>
8
  ForwardIterator remove(ExecutionPolicy&& exec,
9
  ForwardIterator first, ForwardIterator last,
10
  const T& value);
11
 
12
  template<class ForwardIterator, class Predicate>
13
- ForwardIterator remove_if(ForwardIterator first, ForwardIterator last,
14
  Predicate pred);
15
  template<class ExecutionPolicy, class ForwardIterator, class Predicate>
16
  ForwardIterator remove_if(ExecutionPolicy&& exec,
17
  ForwardIterator first, ForwardIterator last,
18
  Predicate pred);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  ```
20
 
21
- *Requires:* The type of `*first` shall satisfy the `MoveAssignable`
22
- requirements (Table  [[tab:moveassignable]]).
 
 
 
 
 
 
 
 
23
 
24
  *Effects:* Eliminates all the elements referred to by iterator `i` in
25
- the range \[`first`, `last`) for which the following corresponding
26
- conditions hold: `*i == value, pred(*i) != false`.
27
 
28
- *Returns:* The end of the resulting range.
29
 
30
- *Remarks:* Stable ([[algorithm.stable]]).
 
 
 
31
 
32
  *Complexity:* Exactly `last - first` applications of the corresponding
33
- predicate.
34
 
35
  [*Note 1*: Each element in the range \[`ret`, `last`), where `ret` is
36
  the returned value, has a valid but unspecified state, because the
37
  algorithms can eliminate elements by moving from elements that were
38
  originally in that range. — *end note*]
39
 
40
  ``` cpp
41
  template<class InputIterator, class OutputIterator, class T>
42
- OutputIterator
43
  remove_copy(InputIterator first, InputIterator last,
44
  OutputIterator result, const T& value);
45
- template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class T>
 
46
  ForwardIterator2
47
  remove_copy(ExecutionPolicy&& exec,
48
  ForwardIterator1 first, ForwardIterator1 last,
49
  ForwardIterator2 result, const T& value);
50
 
51
  template<class InputIterator, class OutputIterator, class Predicate>
52
- OutputIterator
53
  remove_copy_if(InputIterator first, InputIterator last,
54
  OutputIterator result, Predicate pred);
55
- template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class Predicate>
 
56
  ForwardIterator2
57
  remove_copy_if(ExecutionPolicy&& exec,
58
  ForwardIterator1 first, ForwardIterator1 last,
59
  ForwardIterator2 result, Predicate pred);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  ```
61
 
62
- *Requires:* The ranges \[`first`, `last`) and \[`result`,
63
- `result + (last - first)`) shall not overlap. The expression
64
- `*result = *first` shall be valid.
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
  [*Note 2*: For the overloads with an `ExecutionPolicy`, there may be a
67
- performance cost if `iterator_traits<ForwardIterator1>::value_type` is
68
- not `MoveConstructible`
69
- (Table  [[tab:moveconstructible]]). — *end note*]
70
 
71
  *Effects:* Copies all the elements referred to by the iterator `i` in
72
- the range \[`first`, `last`) for which the following corresponding
73
- conditions do not hold: `*i == value, pred(*i) != false`.
74
 
75
- *Returns:* The end of the resulting range.
 
 
 
76
 
77
  *Complexity:* Exactly `last - first` applications of the corresponding
78
- predicate.
79
 
80
- *Remarks:* Stable ([[algorithm.stable]]).
81
 
 
1
  ### Remove <a id="alg.remove">[[alg.remove]]</a>
2
 
3
  ``` cpp
4
  template<class ForwardIterator, class T>
5
+ constexpr ForwardIterator remove(ForwardIterator first, ForwardIterator last,
6
  const T& value);
7
  template<class ExecutionPolicy, class ForwardIterator, class T>
8
  ForwardIterator remove(ExecutionPolicy&& exec,
9
  ForwardIterator first, ForwardIterator last,
10
  const T& value);
11
 
12
  template<class ForwardIterator, class Predicate>
13
+ constexpr ForwardIterator remove_if(ForwardIterator first, ForwardIterator last,
14
  Predicate pred);
15
  template<class ExecutionPolicy, class ForwardIterator, class Predicate>
16
  ForwardIterator remove_if(ExecutionPolicy&& exec,
17
  ForwardIterator first, ForwardIterator last,
18
  Predicate pred);
19
+
20
+ template<permutable I, sentinel_for<I> S, class T, class Proj = identity>
21
+ requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
22
+ constexpr subrange<I> ranges::remove(I first, S last, const T& value, Proj proj = {});
23
+ template<forward_range R, class T, class Proj = identity>
24
+ requires permutable<iterator_t<R>> &&
25
+ indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
26
+ constexpr borrowed_subrange_t<R>
27
+ ranges::remove(R&& r, const T& value, Proj proj = {});
28
+ template<permutable I, sentinel_for<I> S, class Proj = identity,
29
+ indirect_unary_predicate<projected<I, Proj>> Pred>
30
+ constexpr subrange<I> ranges::remove_if(I first, S last, Pred pred, Proj proj = {});
31
+ template<forward_range R, class Proj = identity,
32
+ indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
33
+ requires permutable<iterator_t<R>>
34
+ constexpr borrowed_subrange_t<R>
35
+ ranges::remove_if(R&& r, Pred pred, Proj proj = {});
36
  ```
37
 
38
+ Let E be
39
+
40
+ - `bool(*i == value)` for `remove`;
41
+ - `bool(pred(*i))` for `remove_if`;
42
+ - `bool(invoke(proj, *i) == value)` for `ranges::remove`;
43
+ - `bool(invoke(pred, invoke(proj, *i)))` for `ranges::remove_if`.
44
+
45
+ *Preconditions:* For the algorithms in namespace `std`, the type of
46
+ `*first` meets the *Cpp17MoveAssignable* requirements
47
+ ([[cpp17.moveassignable]]).
48
 
49
  *Effects:* Eliminates all the elements referred to by iterator `i` in
50
+ the range \[`first`, `last`) for which E holds.
 
51
 
52
+ *Returns:* Let j be the end of the resulting range. Returns:
53
 
54
+ - j for the overloads in namespace `std`.
55
+ - `{`j`, last}` for the overloads in namespace `ranges`.
56
+
57
+ *Remarks:* Stable [[algorithm.stable]].
58
 
59
  *Complexity:* Exactly `last - first` applications of the corresponding
60
+ predicate and any projection.
61
 
62
  [*Note 1*: Each element in the range \[`ret`, `last`), where `ret` is
63
  the returned value, has a valid but unspecified state, because the
64
  algorithms can eliminate elements by moving from elements that were
65
  originally in that range. — *end note*]
66
 
67
  ``` cpp
68
  template<class InputIterator, class OutputIterator, class T>
69
+ constexpr OutputIterator
70
  remove_copy(InputIterator first, InputIterator last,
71
  OutputIterator result, const T& value);
72
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
73
+ class T>
74
  ForwardIterator2
75
  remove_copy(ExecutionPolicy&& exec,
76
  ForwardIterator1 first, ForwardIterator1 last,
77
  ForwardIterator2 result, const T& value);
78
 
79
  template<class InputIterator, class OutputIterator, class Predicate>
80
+ constexpr OutputIterator
81
  remove_copy_if(InputIterator first, InputIterator last,
82
  OutputIterator result, Predicate pred);
83
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
84
+ class Predicate>
85
  ForwardIterator2
86
  remove_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 T,
91
+ class Proj = identity>
92
+ requires indirectly_copyable<I, O> &&
93
+ indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
94
+ constexpr ranges::remove_copy_result<I, O>
95
+ ranges::remove_copy(I first, S last, O result, const T& value, Proj proj = {});
96
+ template<input_range R, weakly_incrementable O, class T, class Proj = identity>
97
+ requires indirectly_copyable<iterator_t<R>, O> &&
98
+ indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
99
+ constexpr ranges::remove_copy_result<borrowed_iterator_t<R>, O>
100
+ ranges::remove_copy(R&& r, O result, const T& value, Proj proj = {});
101
+ template<input_iterator I, sentinel_for<I> S, weakly_incrementable O,
102
+ class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred>
103
+ requires indirectly_copyable<I, O>
104
+ constexpr ranges::remove_copy_if_result<I, O>
105
+ ranges::remove_copy_if(I first, S last, O result, Pred pred, Proj proj = {});
106
+ template<input_range R, weakly_incrementable 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::remove_copy_if_result<borrowed_iterator_t<R>, O>
110
+ ranges::remove_copy_if(R&& r, O result, Pred pred, Proj proj = {});
111
  ```
112
 
113
+ Let E be
114
+
115
+ - `bool(*i == value)` for `remove_copy`;
116
+ - `bool(pred(*i))` for `remove_copy_if`;
117
+ - `bool(invoke(proj, *i) == value)` for `ranges::remove_copy`;
118
+ - `bool(invoke(pred, invoke(proj, *i)))` for `ranges::remove_copy_if`.
119
+
120
+ Let N be the number of elements in \[`first`, `last`) for which E is
121
+ `false`.
122
+
123
+ *Mandates:* `*first` is writable [[iterator.requirements.general]] to
124
+ `result`.
125
+
126
+ *Preconditions:* The ranges \[`first`, `last`) and \[`result`,
127
+ `result + (last - first)`) do not overlap.
128
 
129
  [*Note 2*: For the overloads with an `ExecutionPolicy`, there may be a
130
+ performance cost if `iterator_traits<ForwardIterator1>::value_type` does
131
+ not meet the *Cpp17MoveConstructible* ([[cpp17.moveconstructible]])
132
+ requirements. — *end note*]
133
 
134
  *Effects:* Copies all the elements referred to by the iterator `i` in
135
+ the range \[`first`, `last`) for which E is `false`.
 
136
 
137
+ *Returns:*
138
+
139
+ - `result + `N, for the algorithms in namespace `std`.
140
+ - `{last, result + `N`}`, for the algorithms in namespace `ranges`.
141
 
142
  *Complexity:* Exactly `last - first` applications of the corresponding
143
+ predicate and any projection.
144
 
145
+ *Remarks:* Stable [[algorithm.stable]].
146