ranges_find.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef _LIBCPP___ALGORITHM_RANGES_FIND_H
  9. #define _LIBCPP___ALGORITHM_RANGES_FIND_H
  10. #include <__algorithm/ranges_find_if.h>
  11. #include <__config>
  12. #include <__functional/identity.h>
  13. #include <__functional/invoke.h>
  14. #include <__functional/ranges_operations.h>
  15. #include <__iterator/concepts.h>
  16. #include <__iterator/projected.h>
  17. #include <__ranges/access.h>
  18. #include <__ranges/concepts.h>
  19. #include <__ranges/dangling.h>
  20. #include <__utility/forward.h>
  21. #include <__utility/move.h>
  22. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  23. # pragma GCC system_header
  24. #endif
  25. #if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
  26. _LIBCPP_BEGIN_NAMESPACE_STD
  27. namespace ranges {
  28. namespace __find {
  29. struct __fn {
  30. template <input_iterator _Ip, sentinel_for<_Ip> _Sp, class _Tp, class _Proj = identity>
  31. requires indirect_binary_predicate<ranges::equal_to, projected<_Ip, _Proj>, const _Tp*>
  32. _LIBCPP_HIDE_FROM_ABI constexpr
  33. _Ip operator()(_Ip __first, _Sp __last, const _Tp& __value, _Proj __proj = {}) const {
  34. auto __pred = [&](auto&& __e) { return std::forward<decltype(__e)>(__e) == __value; };
  35. return ranges::__find_if_impl(std::move(__first), std::move(__last), __pred, __proj);
  36. }
  37. template <input_range _Rp, class _Tp, class _Proj = identity>
  38. requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t<_Rp>, _Proj>, const _Tp*>
  39. _LIBCPP_HIDE_FROM_ABI constexpr
  40. borrowed_iterator_t<_Rp> operator()(_Rp&& __r, const _Tp& __value, _Proj __proj = {}) const {
  41. auto __pred = [&](auto&& __e) { return std::forward<decltype(__e)>(__e) == __value; };
  42. return ranges::__find_if_impl(ranges::begin(__r), ranges::end(__r), __pred, __proj);
  43. }
  44. };
  45. } // namespace __find
  46. inline namespace __cpo {
  47. inline constexpr auto find = __find::__fn{};
  48. } // namespace __cpo
  49. } // namespace ranges
  50. _LIBCPP_END_NAMESPACE_STD
  51. #endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
  52. #endif // _LIBCPP___ALGORITHM_RANGES_FIND_H