@@ -10,21 +10,55 @@ namespace std::ranges {
1010 sentinel_for<I > S,
1111 class T,
1212 class Proj = identity>
13- requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T* >
13+ requires indirect_binary_predicate<
14+ ranges::equal_to,
15+ projected<I, Proj>,
16+ const T*
17+ >
1418 constexpr ranges::subrange<I >
1519 find_last(I first,
1620 S last,
1721 const T& value,
1822 Proj proj = {}); // (1) C++23
23+ template <forward_iterator I,
24+ sentinel_for<I > S,
25+ class Proj = identity,
26+ class T = projected_value_t<I, Proj>>
27+ requires indirect_binary_predicate<
28+ ranges::equal_to,
29+ projected<I, Proj>,
30+ const T*
31+ >
32+ constexpr ranges::subrange<I >
33+ find_last(I first,
34+ S last,
35+ const T& value,
36+ Proj proj = {}); // (1) C++26
1937
2038 template <forward_range R,
2139 class T,
2240 class Proj = identity>
23- requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R >, Proj>, const T* >
41+ requires indirect_binary_predicate<
42+ ranges::equal_to,
43+ projected<iterator_t<R >, Proj>,
44+ const T*
45+ >
2446 constexpr ranges::borrowed_subrange_t<R >
2547 find_last(R&& r,
2648 const T& value,
2749 Proj proj = {}); // (2) C++23
50+ template <forward_range R,
51+ class Proj = identity,
52+ class T = projected_value_t<iterator_t<R >, Proj>>
53+ requires indirect_binary_predicate<
54+ ranges::equal_to,
55+ projected<iterator_t<R >, Proj>,
56+ const T*
57+ >
58+ constexpr ranges::borrowed_subrange_t<R >
59+ find_last(R&& r,
60+ const T& value,
61+ Proj proj = {}); // (2) C++26
2862}
2963```
3064* forward_iterator[link /reference/iterator/forward_iterator.md]
@@ -50,31 +84,82 @@ namespace std::ranges {
5084最大で `last - first` 回比較を行う
5185
5286
87+ ## 備考
88+ - (1), (2) :
89+ - C++26 : 引数として波カッコ初期化`{}`を受け付ける
90+ ```cpp
91+ std::vector<T> v;
92+ bool found = std::ranges::find_last(r, {a, b});
93+ ```
94+
95+
5396## 例
97+ ### 基本的な使い方
5498```cpp example
5599#include <algorithm>
56100#include <array>
57101#include <iostream>
58102
59103int main() {
60- constexpr std::array v = { 3, 1, 4, 1, 5 };
61- const auto result = std::ranges::find_last(v , 1);
62- if (result.begin() == v .end()) {
104+ constexpr std::array ar = { 3, 1, 4, 1, 5 };
105+ const std::ranges::subrange result = std::ranges::find_last(ar , 1);
106+ if (result.begin() == ar .end()) {
63107 std::cout << "not found" << std::endl;
64108 } else {
65109 std::cout << "found: " << *result.begin() << std::endl;
66- std::cout << " pos: " << std::distance(v .begin(), result.begin()) << std::endl;
110+ std::cout << " pos: " << std::distance(ar .begin(), result.begin()) << std::endl;
67111 }
68112}
69113```
70114* std::ranges::find_last[ color ff0000]
71115
72- ### 出力
116+ #### 出力
73117```
74118found: 1
75119 pos: 3
76120```
77121
122+ ### 波カッコ初期化を入力として使用する (C++26)
123+ ``` cpp example
124+ #include < algorithm>
125+ #include < array>
126+ #include < iostream>
127+
128+ struct Point {
129+ int x;
130+ int y;
131+
132+ bool operator==(const Point& other) const = default;
133+ };
134+
135+ std::ostream& operator<<(std::ostream& os, const Point& p) {
136+ return os << p.x << ',' << p.y;
137+ }
138+
139+ int main() {
140+ constexpr std::array<Point, 3> ar = {{
141+ {1, 2},
142+ {3, 4},
143+ {5, 6}
144+ }};
145+
146+ const std::ranges::subrange result = std::ranges::find_last(ar, {3, 4});
147+ if (result.begin() == ar.end()) {
148+ std::cout << "not found" << std::endl;
149+ } else {
150+ std::cout << "found: " << * result.begin() << std::endl;
151+ std::cout << " pos: " << std::distance(ar.begin(), result.begin()) << std::endl;
152+ }
153+ }
154+ ```
155+ * std::ranges::find_last[color ff0000]
156+
157+ #### 出力
158+ ```
159+ found: 3,4
160+ pos: 1
161+ ```
162+
78163
79164## バージョン
80165### 言語
@@ -87,4 +172,8 @@ found: 1
87172- [Visual C++](/implementation.md#visual_cpp): ??
88173
89174## 参照
90- - [ P1223R5 find_last] ( https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p1223r5.pdf )
175+ - [P1223R5 `find_last`](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p1223r5.pdf)
176+ - [P3217R0 Adjoints to "Enabling list-initialization for algorithms": `find_last`](https://open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3217r0.html)
177+ - C++26で波カッコ初期化 (リスト初期化) に対応した
178+ - 関連文書:
179+ - [P2248R8 Enabling list-initialization for algorithms](https://open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2248r8.html)
0 commit comments