55
66``` cpp
77namespace std {
8- template <class InputIterator, class T>
9- InputIterator find(InputIterator first,
10- InputIterator last,
11- const T& value); // (1) C++03
12-
13- template <class InputIterator, class T>
14- constexpr InputIterator find(InputIterator first,
15- InputIterator last,
16- const T& value); // (1) C++20
17-
18- template<class ExecutionPolicy, class ForwardIterator, class T>
19- ForwardIterator find(ExecutionPolicy&& exec,
20- ForwardIterator first,
21- ForwardIterator last,
22- const T& value); // (2) C++17
8+ template <class InputIterator,
9+ class T>
10+ InputIterator
11+ find(InputIterator first,
12+ InputIterator last,
13+ const T& value); // (1) C++03
14+ template <class InputIterator,
15+ class T>
16+ constexpr InputIterator
17+ find(InputIterator first,
18+ InputIterator last,
19+ const T& value); // (1) C++20
20+ template <class InputIterator,
21+ class T = typename iterator_traits<InputIterator >::value_type>
22+ constexpr InputIterator
23+ find(InputIterator first,
24+ InputIterator last,
25+ const T& value); // (1) C++26
26+
27+ template<class ExecutionPolicy,
28+ class ForwardIterator,
29+ class T>
30+ ForwardIterator
31+ find(ExecutionPolicy&& exec,
32+ ForwardIterator first,
33+ ForwardIterator last,
34+ const T& value); // (2) C++17
35+ template<class ExecutionPolicy,
36+ class ForwardIterator,
37+ class T = typename iterator_traits<InputIterator >::value_type>
38+ ForwardIterator
39+ find(ExecutionPolicy&& exec,
40+ ForwardIterator first,
41+ ForwardIterator last,
42+ const T& value); // (2) C++26
2343}
2444```
2545
@@ -35,7 +55,16 @@ namespace std {
3555最大で `last - first` 回比較を行う
3656
3757
58+ ## 備考
59+ - (1), (2) :
60+ - C++26 : 引数として波カッコ初期化`{}`を受け付ける
61+ ```cpp
62+ std::vector<T> v;
63+ auto it = std::find(v.begin(), v.begin(), {a, b});
64+ ```
65+
3866## 例
67+ ### 基本的な使い方
3968```cpp example
4069#include <algorithm>
4170#include <iostream>
@@ -53,11 +82,46 @@ int main() {
5382```
5483* std::find[ color ff0000]
5584
56- ### 出力
85+ #### 出力
5786```
5887found: 1
5988```
6089
90+ ### 波カッコ初期化を入力として使用する (C++26)
91+ ``` cpp example
92+ #include < algorithm>
93+ #include < iostream>
94+ #include < vector>
95+
96+ struct Point {
97+ int x;
98+ int y;
99+
100+ bool operator==(const Point& other) const = default;
101+ };
102+
103+ int main() {
104+ std::vector<Point > v = {
105+ {1, 2},
106+ {3, 4},
107+ {5, 6}
108+ };
109+
110+ auto it = std::find(v.begin(), v.end(), {3, 4});
111+ if (it == v.end()) {
112+ std::cout << "not found" << std::endl;
113+ } else {
114+ std::cout << "found: " << it->x << "," << it->y << std::endl;
115+ }
116+ }
117+ ```
118+ * std::find[color ff0000]
119+
120+ #### 出力
121+ ```
122+ found: 3,4
123+ ```
124+
61125
62126## 実装例
63127```cpp
@@ -73,3 +137,5 @@ InputIterator find(InputIterator first, InputIterator last, const T& value) {
73137## 参照
74138- [ P0202R3 Add Constexpr Modifiers to Functions in ` <algorithm> ` and ` <utility> ` Headers] ( http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0202r3.html )
75139- [ P0467R2 Iterator Concerns for Parallel Algorithms] ( http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0467r2.html )
140+ - [ P2248R8 Enabling list-initialization for algorithms] ( https://open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2248r8.html )
141+ - C++26で波カッコ初期化 (リスト初期化) に対応した
0 commit comments