Christopher Di Bella | 050b064 | 2021-07-01 09:25:35 -0400 | [diff] [blame] | 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 | |
| 10 | #ifndef _LIBCPP___FUNCTIONAL_DEFAULT_SEARCHER_H |
| 11 | #define _LIBCPP___FUNCTIONAL_DEFAULT_SEARCHER_H |
| 12 | |
| 13 | #include <__algorithm/search.h> |
| 14 | #include <__config> |
| 15 | #include <__functional/operations.h> |
| 16 | #include <__iterator/iterator_traits.h> |
| 17 | #include <utility> |
| 18 | |
| 19 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 20 | #pragma GCC system_header |
| 21 | #endif |
| 22 | |
| 23 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 24 | |
| 25 | #if _LIBCPP_STD_VER > 14 |
| 26 | |
| 27 | // default searcher |
| 28 | template<class _ForwardIterator, class _BinaryPredicate = equal_to<>> |
| 29 | class _LIBCPP_TEMPLATE_VIS default_searcher { |
| 30 | public: |
| 31 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
| 32 | default_searcher(_ForwardIterator __f, _ForwardIterator __l, |
| 33 | _BinaryPredicate __p = _BinaryPredicate()) |
| 34 | : __first_(__f), __last_(__l), __pred_(__p) {} |
| 35 | |
| 36 | template <typename _ForwardIterator2> |
| 37 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
| 38 | pair<_ForwardIterator2, _ForwardIterator2> |
| 39 | operator () (_ForwardIterator2 __f, _ForwardIterator2 __l) const |
| 40 | { |
| 41 | return _VSTD::__search(__f, __l, __first_, __last_, __pred_, |
| 42 | typename iterator_traits<_ForwardIterator>::iterator_category(), |
| 43 | typename iterator_traits<_ForwardIterator2>::iterator_category()); |
| 44 | } |
| 45 | |
| 46 | private: |
| 47 | _ForwardIterator __first_; |
| 48 | _ForwardIterator __last_; |
| 49 | _BinaryPredicate __pred_; |
| 50 | }; |
| 51 | |
| 52 | #endif // _LIBCPP_STD_VER > 14 |
| 53 | |
| 54 | _LIBCPP_END_NAMESPACE_STD |
| 55 | |
| 56 | #endif // _LIBCPP___FUNCTIONAL_DEFAULT_SEARCHER_H |