|
14 | 14 | #include <__functional/invoke.h>
|
15 | 15 | #include <__functional/ranges_operations.h>
|
16 | 16 | #include <__iterator/concepts.h>
|
| 17 | +<<<<<<< HEAD |
17 | 18 | #include <__iterator/indirectly_comparable.h>
|
18 | 19 | #include <__iterator/next.h>
|
19 | 20 | #include <__iterator/prev.h>
|
|
23 | 24 | #include <__ranges/subrange.h>
|
24 | 25 | #include <__utility/forward.h>
|
25 | 26 | #include <__utility/move.h>
|
| 27 | +======= |
| 28 | +#include <__iterator/projected.h> |
| 29 | +#include <__ranges/access.h> |
| 30 | +#include <__ranges/concepts.h> |
| 31 | +#include <__ranges/dangling.h> |
| 32 | +#include <__utility/forward.h> |
| 33 | +#include <__utility/move.h> |
| 34 | +#include <optional> |
| 35 | +>>>>>>> cfed7b885225 (Algorithms for ranges_find_last, find_last_if, and find_last_if_not) |
26 | 36 |
|
27 | 37 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
28 | 38 | # pragma GCC system_header
|
|
31 | 41 | _LIBCPP_PUSH_MACROS
|
32 | 42 | #include <__undef_macros>
|
33 | 43 |
|
| 44 | +<<<<<<< HEAD |
34 | 45 | #if _LIBCPP_STD_VER >= 23
|
| 46 | +======= |
| 47 | +#if _LIBCPP_STD_VER >= 20 |
| 48 | +>>>>>>> cfed7b885225 (Algorithms for ranges_find_last, find_last_if, and find_last_if_not) |
35 | 49 |
|
36 | 50 | _LIBCPP_BEGIN_NAMESPACE_STD
|
37 | 51 |
|
38 | 52 | namespace ranges {
|
39 | 53 |
|
| 54 | +<<<<<<< HEAD |
40 | 55 | template <class _Iter, class _Sent, class _Pred, class _Proj>
|
41 | 56 | _LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter>
|
42 | 57 | __find_last_impl(_Iter __first, _Sent __last, _Pred __pred, _Proj& __proj) {
|
@@ -159,11 +174,51 @@ inline constexpr auto find_last = __find_last{};
|
159 | 174 | inline constexpr auto find_last_if = __find_last_if{};
|
160 | 175 | inline constexpr auto find_last_if_not = __find_last_if_not{};
|
161 | 176 | } // namespace __cpo
|
| 177 | +======= |
| 178 | +namespace __find_last { |
| 179 | + |
| 180 | +struct __fn { |
| 181 | + template <forward_iterator _Ip, sentinel_for<_Ip> _Sp, class _Tp, class _Proj = identity> |
| 182 | + requires indirect_binary_predicate<ranges::equal_to, projected<_Ip, _Proj>, const _Tp*> |
| 183 | + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr subrange<_Ip> |
| 184 | + operator()(_Ip __first, _Sp __last, const _Tp& __value, _Proj __proj = {}) const { |
| 185 | + std::optional<_Ip> __found; |
| 186 | + for (; __first != __last; ++__first) { |
| 187 | + if (std::invoke(__proj, *__first) == __value) { |
| 188 | + __found = __first; |
| 189 | + } |
| 190 | + } |
| 191 | + if (!__found) |
| 192 | + return {__first, __first}; |
| 193 | + return {*__found, std::ranges::next(*__found, __last)}; |
| 194 | + } |
| 195 | + |
| 196 | + template <forward_range _Rp, class _Tp, class _Proj = identity> |
| 197 | + requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t<_Rp>, _Proj>, const _Tp*> |
| 198 | + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr borrowed_subrange_t<_Rp> |
| 199 | + operator()(_Rp&& __r, const _Tp& __value, _Proj __proj = {}) const { |
| 200 | + return this->operator()(ranges::begin(__r), ranges::end(__r), __value, std::ref(__proj)); |
| 201 | + } |
| 202 | +}; |
| 203 | + |
| 204 | +} // namespace __find_last |
| 205 | + |
| 206 | +inline namespace __cpo { |
| 207 | +inline constexpr auto find_last = __find_last::__fn{}; |
| 208 | +inline constexpr auto find_last_if = __find_last::__fn{}; |
| 209 | +inline constexpr auto find_last_if_not = __find_last::__fn{}; |
| 210 | +} // namespace __cpo |
| 211 | + |
| 212 | +>>>>>>> cfed7b885225 (Algorithms for ranges_find_last, find_last_if, and find_last_if_not) |
162 | 213 | } // namespace ranges
|
163 | 214 |
|
164 | 215 | _LIBCPP_END_NAMESPACE_STD
|
165 | 216 |
|
| 217 | +<<<<<<< HEAD |
166 | 218 | #endif // _LIBCPP_STD_VER >= 23
|
| 219 | +======= |
| 220 | +#endif // _LIBCPP_STD_VER >= 20 |
| 221 | +>>>>>>> cfed7b885225 (Algorithms for ranges_find_last, find_last_if, and find_last_if_not) |
167 | 222 |
|
168 | 223 | _LIBCPP_POP_MACROS
|
169 | 224 |
|
|
0 commit comments