Skip to content

Commit 260bfc5

Browse files
committed
algorithm/remove_copy : C++26波カッコ初期化に対応 #1311
1 parent b810699 commit 260bfc5

File tree

2 files changed

+167
-9
lines changed

2 files changed

+167
-9
lines changed

reference/algorithm/ranges_remove_copy.md

Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,23 @@ namespace std::ranges {
2323
O result,
2424
const T& value,
2525
Proj proj = {}); // (1) C++20
26+
template <input_iterator I,
27+
sentinel_for<I> S,
28+
weakly_incrementable O,
29+
class Proj = identity,
30+
class T = projected_value_t<I, Proj>>
31+
requires indirectly_copyable<I, O> &&
32+
indirect_binary_predicate<
33+
ranges::equal_to,
34+
projected<I, Proj>,
35+
const T*
36+
>
37+
constexpr remove_copy_result<I, O>
38+
remove_copy(I first,
39+
S last,
40+
O result,
41+
const T& value,
42+
Proj proj = {}); // (1) C++26
2643

2744
template <input_range R,
2845
weakly_incrementable O,
@@ -39,6 +56,21 @@ namespace std::ranges {
3956
O result,
4057
const T& value,
4158
Proj proj = {}); // (2) C++20
59+
template <input_range R,
60+
weakly_incrementable O,
61+
class Proj = identity,
62+
class T = projected_value_t<iterator_t<R>, Proj>>
63+
requires indirectly_copyable<iterator_t<R>, O> &&
64+
indirect_binary_predicate<
65+
ranges::equal_to,
66+
projected<iterator_t<R>, Proj>,
67+
const T*
68+
>
69+
constexpr remove_copy_result<borrowed_iterator_t<R>, O>
70+
remove_copy(R&& r,
71+
O result,
72+
const T& value,
73+
Proj proj = {}); // (2) C++26
4274
}
4375
```
4476
* input_iterator[link /reference/iterator/input_iterator.md]
@@ -76,10 +108,17 @@ namespace std::ranges {
76108
77109
78110
## 備考
79-
安定。
111+
- 安定。
112+
- (1), (2) :
113+
- C++26 : 引数として波カッコ初期化`{}`を受け付ける
114+
```cpp
115+
std::vector<T> v;
116+
std::ranges::remove_copy(v, result, {a, b});
117+
```
80118
81119
82120
## 例
121+
### 基本的な使い方
83122
```cpp example
84123
#include <algorithm>
85124
#include <iostream>
@@ -95,11 +134,53 @@ int main() {
95134
```
96135
* std::ranges::remove_copy[color ff0000]
97136

98-
### 出力
137+
#### 出力
99138
```
100139
2,3,2,
101140
```
102141

142+
### 波カッコ初期化を入力として使用する (C++26)
143+
```cpp example
144+
#include <algorithm>
145+
#include <iostream>
146+
#include <vector>
147+
#include <iterator>
148+
149+
struct Point {
150+
int x;
151+
int y;
152+
153+
bool operator==(const Point& other) const = default;
154+
};
155+
156+
std::ostream& operator<<(std::ostream& os, const Point& p) {
157+
return os << p.x << "," << p.y;
158+
}
159+
160+
int main() {
161+
std::vector<Point> v = {
162+
{1, 2},
163+
{3, 4},
164+
{5, 6},
165+
{1, 2},
166+
};
167+
168+
// 値{1, 2}を除去した結果を出力する
169+
std::ranges::remove_copy(
170+
v,
171+
std::ostream_iterator<Point>(std::cout, "\n"),
172+
{1, 2}
173+
);
174+
}
175+
```
176+
* std::ranges::remove_copy[color ff0000]
177+
178+
#### 出力
179+
```
180+
3,4
181+
5,6
182+
```
183+
103184
104185
## バージョン
105186
### 言語
@@ -113,3 +194,5 @@ int main() {
113194
114195
## 参照
115196
- [N4861 25 Algorithms library](https://timsong-cpp.github.io/cppwp/n4861/algorithms)
197+
- [P2248R8 Enabling list-initialization for algorithms](https://open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2248r8.html)
198+
- C++26で波カッコ初期化 (リスト初期化) に対応した

reference/algorithm/remove_copy.md

Lines changed: 82 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,59 @@
55

66
```cpp
77
namespace std {
8-
template <class InputIterator, class OutputIterator, class T>
8+
template <class InputIterator,
9+
class OutputIterator,
10+
class T>
911
OutputIterator
1012
remove_copy(InputIterator first,
1113
InputIterator last,
1214
OutputIterator result,
1315
const T& value); // (1) C++03
14-
15-
template <class InputIterator, class OutputIterator, class T>
16+
template <class InputIterator,
17+
class OutputIterator,
18+
class T>
1619
constexpr OutputIterator
1720
remove_copy(InputIterator first,
1821
InputIterator last,
1922
OutputIterator result,
2023
const T& value); // (1) C++20
24+
template <class InputIterator,
25+
class OutputIterator,
26+
class T = typename iterator_traits<InputIterator>::value_type>
27+
constexpr OutputIterator
28+
remove_copy(InputIterator first,
29+
InputIterator last,
30+
OutputIterator result,
31+
const T& value); // (1) C++26
2132

22-
template <class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
33+
template <class ExecutionPolicy,
34+
class ForwardIterator1,
35+
class ForwardIterator2,
2336
class T>
2437
ForwardIterator2
2538
remove_copy(ExecutionPolicy&& exec,
2639
ForwardIterator1 first,
2740
ForwardIterator1 last,
2841
ForwardIterator2 result,
2942
const T& value); // (2) C++17
43+
template <class ExecutionPolicy,
44+
class ForwardIterator1,
45+
class ForwardIterator2,
46+
class T = typename iterator_traits<ForwardIterator1>::value_type>
47+
ForwardIterator2
48+
remove_copy(ExecutionPolicy&& exec,
49+
ForwardIterator1 first,
50+
ForwardIterator1 last,
51+
ForwardIterator2 result,
52+
const T& value); // (2) C++26
3053
}
3154
```
3255
3356
## 概要
3457
イテレータ範囲`[first, last)`から指定された要素を除け、その結果を出力の範囲へコピーする。
3558
3659
37-
## テンプレートパラメータ制約
60+
## 適格要件
3861
- `*result = *first` という式が有効であること
3962
4063
@@ -55,10 +78,17 @@ namespace std {
5578
5679
5780
## 備考
58-
安定。
81+
- 安定。
82+
- (1), (2) :
83+
- C++26 : 引数として波カッコ初期化`{}`を受け付ける
84+
```cpp
85+
std::vector<T> v;
86+
std::remove_copy(v.begin(), v.end(), result, {a, b});
87+
```
5988
6089
6190
## 例
91+
### 基本的な使い方
6292
```cpp example
6393
#include <algorithm>
6494
#include <iostream>
@@ -75,11 +105,54 @@ int main() {
75105
```
76106
* std::remove_copy[color ff0000]
77107

78-
### 出力
108+
#### 出力
79109
```
80110
2,3,2,
81111
```
82112

113+
### 波カッコ初期化を入力として使用する (C++26)
114+
```cpp example
115+
#include <algorithm>
116+
#include <iostream>
117+
#include <vector>
118+
#include <iterator>
119+
120+
struct Point {
121+
int x;
122+
int y;
123+
124+
bool operator==(const Point& other) const = default;
125+
};
126+
127+
std::ostream& operator<<(std::ostream& os, const Point& p) {
128+
return os << p.x << "," << p.y;
129+
}
130+
131+
int main() {
132+
std::vector<Point> v = {
133+
{1, 2},
134+
{3, 4},
135+
{5, 6},
136+
{1, 2},
137+
};
138+
139+
// 値{1, 2}を除去した結果を出力する
140+
std::remove_copy(
141+
v.begin(),
142+
v.end(),
143+
std::ostream_iterator<Point>(std::cout, "\n"),
144+
{1, 2}
145+
);
146+
}
147+
```
148+
* std::remove_copy[color ff0000]
149+
150+
#### 出力
151+
```
152+
3,4
153+
5,6
154+
```
155+
83156
84157
## 実装例
85158
```cpp
@@ -97,3 +170,5 @@ OutputIterator remove_copy(InputIterator first, InputIterator last,
97170
## 参照
98171
- [P0202R3 Add Constexpr Modifiers to Functions in `<algorithm>` and `<utility>` Headers](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0202r3.html)
99172
- [P0467R2 Iterator Concerns for Parallel Algorithms](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0467r2.html)
173+
- [P2248R8 Enabling list-initialization for algorithms](https://open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2248r8.html)
174+
- C++26で波カッコ初期化 (リスト初期化) に対応した

0 commit comments

Comments
 (0)