xref: /freebsd-src/contrib/llvm-project/libcxx/include/__algorithm/ranges_find.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
181ad6265SDimitry Andric //===----------------------------------------------------------------------===//
281ad6265SDimitry Andric //
381ad6265SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
481ad6265SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
581ad6265SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
681ad6265SDimitry Andric //
781ad6265SDimitry Andric //===----------------------------------------------------------------------===//
881ad6265SDimitry Andric 
981ad6265SDimitry Andric #ifndef _LIBCPP___ALGORITHM_RANGES_FIND_H
1081ad6265SDimitry Andric #define _LIBCPP___ALGORITHM_RANGES_FIND_H
1181ad6265SDimitry Andric 
1206c3fb27SDimitry Andric #include <__algorithm/find.h>
1381ad6265SDimitry Andric #include <__algorithm/ranges_find_if.h>
1406c3fb27SDimitry Andric #include <__algorithm/unwrap_range.h>
1581ad6265SDimitry Andric #include <__config>
1681ad6265SDimitry Andric #include <__functional/identity.h>
1781ad6265SDimitry Andric #include <__functional/invoke.h>
1881ad6265SDimitry Andric #include <__functional/ranges_operations.h>
1981ad6265SDimitry Andric #include <__iterator/concepts.h>
2081ad6265SDimitry Andric #include <__iterator/projected.h>
2181ad6265SDimitry Andric #include <__ranges/access.h>
2281ad6265SDimitry Andric #include <__ranges/concepts.h>
2381ad6265SDimitry Andric #include <__ranges/dangling.h>
2481ad6265SDimitry Andric #include <__utility/forward.h>
2581ad6265SDimitry Andric #include <__utility/move.h>
2681ad6265SDimitry Andric 
2781ad6265SDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2881ad6265SDimitry Andric #  pragma GCC system_header
2981ad6265SDimitry Andric #endif
3081ad6265SDimitry Andric 
31b3edf446SDimitry Andric _LIBCPP_PUSH_MACROS
32b3edf446SDimitry Andric #include <__undef_macros>
33b3edf446SDimitry Andric 
3406c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 20
3581ad6265SDimitry Andric 
3681ad6265SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD
3781ad6265SDimitry Andric 
3881ad6265SDimitry Andric namespace ranges {
3981ad6265SDimitry Andric namespace __find {
4081ad6265SDimitry Andric struct __fn {
4106c3fb27SDimitry Andric   template <class _Iter, class _Sent, class _Tp, class _Proj>
4206c3fb27SDimitry Andric   _LIBCPP_HIDE_FROM_ABI static constexpr _Iter
4306c3fb27SDimitry Andric   __find_unwrap(_Iter __first, _Sent __last, const _Tp& __value, _Proj& __proj) {
4406c3fb27SDimitry Andric     if constexpr (forward_iterator<_Iter>) {
4506c3fb27SDimitry Andric       auto [__first_un, __last_un] = std::__unwrap_range(__first, std::move(__last));
4606c3fb27SDimitry Andric       return std::__rewrap_range<_Sent>(
47*0fca6ea1SDimitry Andric           std::move(__first), std::__find(std::move(__first_un), std::move(__last_un), __value, __proj));
4806c3fb27SDimitry Andric     } else {
49*0fca6ea1SDimitry Andric       return std::__find(std::move(__first), std::move(__last), __value, __proj);
5006c3fb27SDimitry Andric     }
5106c3fb27SDimitry Andric   }
5206c3fb27SDimitry Andric 
5381ad6265SDimitry Andric   template <input_iterator _Ip, sentinel_for<_Ip> _Sp, class _Tp, class _Proj = identity>
5481ad6265SDimitry Andric     requires indirect_binary_predicate<ranges::equal_to, projected<_Ip, _Proj>, const _Tp*>
55*0fca6ea1SDimitry Andric   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Ip
5606c3fb27SDimitry Andric   operator()(_Ip __first, _Sp __last, const _Tp& __value, _Proj __proj = {}) const {
5706c3fb27SDimitry Andric     return __find_unwrap(std::move(__first), std::move(__last), __value, __proj);
5881ad6265SDimitry Andric   }
5981ad6265SDimitry Andric 
6081ad6265SDimitry Andric   template <input_range _Rp, class _Tp, class _Proj = identity>
6181ad6265SDimitry Andric     requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t<_Rp>, _Proj>, const _Tp*>
62*0fca6ea1SDimitry Andric   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Rp>
6306c3fb27SDimitry Andric   operator()(_Rp&& __r, const _Tp& __value, _Proj __proj = {}) const {
6406c3fb27SDimitry Andric     return __find_unwrap(ranges::begin(__r), ranges::end(__r), __value, __proj);
6581ad6265SDimitry Andric   }
6681ad6265SDimitry Andric };
6781ad6265SDimitry Andric } // namespace __find
6881ad6265SDimitry Andric 
6981ad6265SDimitry Andric inline namespace __cpo {
7081ad6265SDimitry Andric inline constexpr auto find = __find::__fn{};
7181ad6265SDimitry Andric } // namespace __cpo
7281ad6265SDimitry Andric } // namespace ranges
7381ad6265SDimitry Andric 
7481ad6265SDimitry Andric _LIBCPP_END_NAMESPACE_STD
7581ad6265SDimitry Andric 
7606c3fb27SDimitry Andric #endif // _LIBCPP_STD_VER >= 20
7781ad6265SDimitry Andric 
78b3edf446SDimitry Andric _LIBCPP_POP_MACROS
79b3edf446SDimitry Andric 
8081ad6265SDimitry Andric #endif // _LIBCPP___ALGORITHM_RANGES_FIND_H
81