xref: /llvm-project/libcxx/include/__algorithm/find_first_of.h (revision b905bcc5090cde734e8b7bbceae13bd5a606cc14)
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 <__algorithm/comp.h>
14 #include <__config>
15 
16 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17 #  pragma GCC system_header
18 #endif
19 
20 _LIBCPP_BEGIN_NAMESPACE_STD
21 
22 template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
23 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator1 __find_first_of_ce(
24     _ForwardIterator1 __first1,
25     _ForwardIterator1 __last1,
26     _ForwardIterator2 __first2,
27     _ForwardIterator2 __last2,
28     _BinaryPredicate&& __pred) {
29   for (; __first1 != __last1; ++__first1)
30     for (_ForwardIterator2 __j = __first2; __j != __last2; ++__j)
31       if (__pred(*__first1, *__j))
32         return __first1;
33   return __last1;
34 }
35 
36 template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
37 [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 find_first_of(
38     _ForwardIterator1 __first1,
39     _ForwardIterator1 __last1,
40     _ForwardIterator2 __first2,
41     _ForwardIterator2 __last2,
42     _BinaryPredicate __pred) {
43   return std::__find_first_of_ce(__first1, __last1, __first2, __last2, __pred);
44 }
45 
46 template <class _ForwardIterator1, class _ForwardIterator2>
47 [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 find_first_of(
48     _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) {
49   return std::__find_first_of_ce(__first1, __last1, __first2, __last2, __equal_to());
50 }
51 
52 _LIBCPP_END_NAMESPACE_STD
53 
54 #endif // _LIBCPP___ALGORITHM_FIND_FIRST_OF_H
55