default_searcher.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  3. //
  4. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. // See https://llvm.org/LICENSE.txt for license information.
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef _LIBCPP___FUNCTIONAL_DEFAULT_SEARCHER_H
  10. #define _LIBCPP___FUNCTIONAL_DEFAULT_SEARCHER_H
  11. #include <__algorithm/search.h>
  12. #include <__config>
  13. #include <__functional/identity.h>
  14. #include <__functional/operations.h>
  15. #include <__iterator/iterator_traits.h>
  16. #include <__utility/pair.h>
  17. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  18. # pragma GCC system_header
  19. #endif
  20. _LIBCPP_BEGIN_NAMESPACE_STD
  21. #if _LIBCPP_STD_VER > 14
  22. // default searcher
  23. template<class _ForwardIterator, class _BinaryPredicate = equal_to<>>
  24. class _LIBCPP_TEMPLATE_VIS default_searcher {
  25. public:
  26. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  27. default_searcher(_ForwardIterator __f, _ForwardIterator __l,
  28. _BinaryPredicate __p = _BinaryPredicate())
  29. : __first_(__f), __last_(__l), __pred_(__p) {}
  30. template <typename _ForwardIterator2>
  31. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  32. pair<_ForwardIterator2, _ForwardIterator2>
  33. operator () (_ForwardIterator2 __f, _ForwardIterator2 __l) const
  34. {
  35. auto __proj = __identity();
  36. return std::__search_impl(__f, __l, __first_, __last_, __pred_, __proj, __proj);
  37. }
  38. private:
  39. _ForwardIterator __first_;
  40. _ForwardIterator __last_;
  41. _BinaryPredicate __pred_;
  42. };
  43. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(default_searcher);
  44. #endif // _LIBCPP_STD_VER > 14
  45. _LIBCPP_END_NAMESPACE_STD
  46. #endif // _LIBCPP___FUNCTIONAL_DEFAULT_SEARCHER_H