55
66``` cpp
77namespace 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```
801102,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