xref: /freebsd-src/contrib/llvm-project/libcxx/include/__algorithm/find_first_of.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1fe6060f1SDimitry Andric // -*- C++ -*-
2fe6060f1SDimitry Andric //===----------------------------------------------------------------------===//
3fe6060f1SDimitry Andric //
4fe6060f1SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5fe6060f1SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
6fe6060f1SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7fe6060f1SDimitry Andric //
8fe6060f1SDimitry Andric //===----------------------------------------------------------------------===//
9fe6060f1SDimitry Andric 
10fe6060f1SDimitry Andric #ifndef _LIBCPP___ALGORITHM_FIND_FIRST_OF_H
11fe6060f1SDimitry Andric #define _LIBCPP___ALGORITHM_FIND_FIRST_OF_H
12fe6060f1SDimitry Andric 
13fe6060f1SDimitry Andric #include <__algorithm/comp.h>
1404eeddc0SDimitry Andric #include <__config>
15fe6060f1SDimitry Andric #include <__iterator/iterator_traits.h>
16fe6060f1SDimitry Andric 
17fe6060f1SDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18fe6060f1SDimitry Andric #  pragma GCC system_header
19fe6060f1SDimitry Andric #endif
20fe6060f1SDimitry Andric 
21fe6060f1SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD
22fe6060f1SDimitry Andric 
23fe6060f1SDimitry Andric template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
24cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator1 __find_first_of_ce(
25cb14a3feSDimitry Andric     _ForwardIterator1 __first1,
26fe6060f1SDimitry Andric     _ForwardIterator1 __last1,
27fe6060f1SDimitry Andric     _ForwardIterator2 __first2,
2861cfbce3SDimitry Andric     _ForwardIterator2 __last2,
2961cfbce3SDimitry Andric     _BinaryPredicate&& __pred) {
30fe6060f1SDimitry Andric   for (; __first1 != __last1; ++__first1)
31fe6060f1SDimitry Andric     for (_ForwardIterator2 __j = __first2; __j != __last2; ++__j)
32fe6060f1SDimitry Andric       if (__pred(*__first1, *__j))
33fe6060f1SDimitry Andric         return __first1;
34fe6060f1SDimitry Andric   return __last1;
35fe6060f1SDimitry Andric }
36fe6060f1SDimitry Andric 
37fe6060f1SDimitry Andric template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
38*0fca6ea1SDimitry Andric _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 find_first_of(
39cb14a3feSDimitry Andric     _ForwardIterator1 __first1,
40cb14a3feSDimitry Andric     _ForwardIterator1 __last1,
41cb14a3feSDimitry Andric     _ForwardIterator2 __first2,
42cb14a3feSDimitry Andric     _ForwardIterator2 __last2,
43cb14a3feSDimitry Andric     _BinaryPredicate __pred) {
445f757f3fSDimitry Andric   return std::__find_first_of_ce(__first1, __last1, __first2, __last2, __pred);
45fe6060f1SDimitry Andric }
46fe6060f1SDimitry Andric 
47fe6060f1SDimitry Andric template <class _ForwardIterator1, class _ForwardIterator2>
48*0fca6ea1SDimitry Andric _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 find_first_of(
49fe6060f1SDimitry Andric     _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) {
50bdd1243dSDimitry Andric   return std::__find_first_of_ce(__first1, __last1, __first2, __last2, __equal_to());
51fe6060f1SDimitry Andric }
52fe6060f1SDimitry Andric 
53fe6060f1SDimitry Andric _LIBCPP_END_NAMESPACE_STD
54fe6060f1SDimitry Andric 
55fe6060f1SDimitry Andric #endif // _LIBCPP___ALGORITHM_FIND_FIRST_OF_H
56