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___ALGORITHM_FIND_FIRST_OF_H
11 #define _LIBCPP___ALGORITHM_FIND_FIRST_OF_H
12 
13 #include <__config>
14 #include <__algorithm/comp.h>
15 #include <__iterator/iterator_traits.h>
16 
17 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18 #pragma GCC system_header
19 #endif
20 
21 _LIBCPP_PUSH_MACROS
22 #include <__undef_macros>
23 
24 _LIBCPP_BEGIN_NAMESPACE_STD
25 
26 template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
27 _LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator1 __find_first_of_ce(_ForwardIterator1 __first1,
28                                                                    _ForwardIterator1 __last1,
29                                                                    _ForwardIterator2 __first2,
30                                                                    _ForwardIterator2 __last2, _BinaryPredicate __pred) {
31   for (; __first1 != __last1; ++__first1)
32     for (_ForwardIterator2 __j = __first2; __j != __last2; ++__j)
33       if (__pred(*__first1, *__j))
34         return __first1;
35   return __last1;
36 }
37 
38 template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
39 _LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator1
40 find_first_of(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
41               _ForwardIterator2 __last2, _BinaryPredicate __pred) {
42   return _VSTD::__find_first_of_ce(__first1, __last1, __first2, __last2, __pred);
43 }
44 
45 template <class _ForwardIterator1, class _ForwardIterator2>
46 _LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator1 find_first_of(
47     _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) {
48   typedef typename iterator_traits<_ForwardIterator1>::value_type __v1;
49   typedef typename iterator_traits<_ForwardIterator2>::value_type __v2;
50   return _VSTD::__find_first_of_ce(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>());
51 }
52 
53 _LIBCPP_END_NAMESPACE_STD
54 
55 _LIBCPP_POP_MACROS
56 
57 #endif // _LIBCPP___ALGORITHM_FIND_FIRST_OF_H
58