default_searcher.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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/operations.h>
  14. #include <__iterator/iterator_traits.h>
  15. #include <__utility/pair.h>
  16. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  17. # pragma GCC system_header
  18. #endif
  19. _LIBCPP_BEGIN_NAMESPACE_STD
  20. #if _LIBCPP_STD_VER > 14
  21. // default searcher
  22. template<class _ForwardIterator, class _BinaryPredicate = equal_to<>>
  23. class _LIBCPP_TEMPLATE_VIS default_searcher {
  24. public:
  25. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
  26. default_searcher(_ForwardIterator __f, _ForwardIterator __l,
  27. _BinaryPredicate __p = _BinaryPredicate())
  28. : __first_(__f), __last_(__l), __pred_(__p) {}
  29. template <typename _ForwardIterator2>
  30. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
  31. pair<_ForwardIterator2, _ForwardIterator2>
  32. operator () (_ForwardIterator2 __f, _ForwardIterator2 __l) const
  33. {
  34. return _VSTD::__search(__f, __l, __first_, __last_, __pred_,
  35. typename iterator_traits<_ForwardIterator>::iterator_category(),
  36. typename iterator_traits<_ForwardIterator2>::iterator_category());
  37. }
  38. private:
  39. _ForwardIterator __first_;
  40. _ForwardIterator __last_;
  41. _BinaryPredicate __pred_;
  42. };
  43. #endif // _LIBCPP_STD_VER > 14
  44. _LIBCPP_END_NAMESPACE_STD
  45. #endif // _LIBCPP___FUNCTIONAL_DEFAULT_SEARCHER_H